我收到错误" variable EQ has no value
"当我运行以下代码时。如何克服这个错误?
(defun add_book(bookref title author publisher)
(setf (get bookref 'title) title)
(setf (get bookref 'author) author)
(setf (get bookref 'publisher) publisher)
(setq library (cons bookref library))
bookref)
(defun retrieve_by (property value)
(setq result nil)
(do ((L library (cdr L)))
((NULL L) result)
(cond (EQ (get (car L) property) value)
(cons (car L) result))))
答案 0 :(得分:4)
也许更好的格式化和SBCL编译器的输出将帮助您。请参阅编译器警告。尝试查阅Lisp引用以查找各种构造的语法:http://lispdoc.com
* (defun add_book(bookref title author publisher)
(setf (get bookref 'title) title)
(setf (get bookref 'author) author)
(setf (get bookref 'publisher) publisher)
(setq library (cons bookref library))
bookref)
; in: DEFUN ADD_BOOK
; (SETQ LIBRARY (CONS BOOKREF LIBRARY))
;
; caught WARNING:
; undefined variable: LIBRARY
;
; compilation unit finished
; Undefined variable:
; LIBRARY
; caught 1 WARNING condition
ADD_BOOK
* (defun retrieve_by (property value)
(setq result nil)
(do ((L library (cdr L)))
((NULL L) result)
(cond (EQ (get (car L) property) value)
(cons (car L) result))))
; in: DEFUN RETRIEVE_BY
; (COND (EQ (GET (CAR L) PROPERTY) VALUE) (CONS (CAR L) RESULT))
; --> IF COND
; ==>
; (IF CONS
; (PROGN (CAR L) RESULT)
; NIL)
;
; caught WARNING:
; undefined variable: CONS
; ==>
; (IF EQ
; (PROGN (GET (CAR L) PROPERTY) VALUE)
; (COND (CONS (CAR L) RESULT)))
;
; caught WARNING:
; undefined variable: EQ
; (DO ((L LIBRARY (CDR L)))
; ((NULL L) RESULT)
; (COND (EQ (GET (CAR L) PROPERTY) VALUE) (CONS (CAR L) RESULT)))
; --> BLOCK
; ==>
; (LET ((L LIBRARY))
; (TAGBODY
; (GO #:G1)
; #:G0
; (TAGBODY (COND (EQ # VALUE) (CONS # RESULT)))
; (PSETQ L (CDR L))
; #:G1
; (UNLESS (NULL L) (GO #:G0))
; (RETURN-FROM NIL (PROGN RESULT))))
;
; caught WARNING:
; undefined variable: LIBRARY
; (SETQ RESULT NIL)
;
; caught WARNING:
; undefined variable: RESULT
;
; compilation unit finished
; Undefined variables:
; CONS EQ LIBRARY RESULT
; caught 4 WARNING conditions
RETRIEVE_BY
*