2

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)
    nil))

(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)
                           (cond
                            ((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?

2

Use #' for quoting:

(defun test ()
  (cl-labels ((square (x) (* x x)))
    (mapcar #'square '(1 2 3))))
(test)
;; =>
;; (1 4 9)
  • 1
    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 '16 at 7:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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