3

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?

Drew
  • 77,472
  • 10
  • 114
  • 243
Srv19
  • 489
  • 4
  • 15

1 Answers1

4

Use #' for quoting:

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