I am trying to use cl-labels, but i have run into errors i do not understand. Here is elisp code i am using:

(defun nthelt (N ARRAY)
  "Behaves like nth but for arrays"
  (if (and (>= N 0)
           (< N (length ARRAY)))
      (elt ARRAY N)

(defvar *neraser-board*
     [(*sync* . 7)
      (*cell* . 3)
      (*cell* . 2)
      (*cell* . 2)])

(defun neraser-check-victory ()
  "Check if victory or loss condition (weak) has been reached"
  (cl-labels ((victory-key (board-elem)
                            ((eq (car board-elem) '*c-sync*)
                             (nthelt 0 (cdr board-elem)))
                            ((eq (car board-elem) '*sync*)
                             (cdr board-elem))
                            (t 0))))
    (let ((victory-index (position 0 *neraser-board*
                                   :key 'victory-key
                                   :test-not 'eq)))
      (if (null victory-index)
          (message "Congratulations!")))))

When i try to run neraser-check-victory, i get this error:

Debugger entered--Lisp error: (void-function victory-key)

How can i resolve this error?

1 Answer 1


Use #' for quoting:

(defun test ()
  (cl-labels ((square (x) (* x x)))
    (mapcar #'square '(1 2 3))))
;; =>
;; (1 4 9)
  • 3
    Consider explaining the use of sharp-quoting, as it's used in a much more limited way in elisp than in CL.
    – wasamasa
    May 19, 2016 at 7:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.