2015-07-20 70 views
0

當我運行以下代碼時,出現錯誤「variable EQ has no value」。如何克服這個錯誤?common lisp編程EQ錯誤

(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)))) 
+1

請訪問[幫助]頁面查看提問的基本內容。 – ckruczek

回答

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 
*