2011-09-20 65 views
2

對不起我的英文不好:) 我有口齒不清的問題。我在這裏向http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-10.html SBCL 鍵入代碼變量B是綁定在Lisp中

* (define a 3) 

; in: DEFINE A 
;  (DEFINE A 3) 
; 
; caught WARNING: 
; undefined variable: A 
; 
; caught STYLE-WARNING: 
; undefined function: DEFINE 
; 
; compilation unit finished 
; Undefined function: 
;  DEFINE 
; Undefined variable: 
;  A 
; caught 1 WARNING condition 
; caught 1 STYLE-WARNING condition 

debugger invoked on a UNBOUND-VARIABLE in thread #<THREAD 
               "initial thread" RUNNING 
               {10029211E1}>: 
The variable A is unbound. 

Type HELP for debugger help, or (SB-EXT:QUIT) to exit from SBCL. 

restarts (invokable by number or by possibly-abbreviated name): 
0: [ABORT] Exit debugger, returning to top level. 

有人給我幫助嗎?

+4

SICP使用方案,一個Lisp的方言。 SBCL實現另一種Lisp方言Common Lisp。我認爲你需要使用Scheme實現。 –

回答

2

你定義一個函數defun定義:

(defun a() 3) 

你的情況,你想調用函數與自變量的......這當然是不確定的界定的。

更一般地,您提供的參數傳遞給函數like this

(defun param-taking-fun (a b) 
    (+ a b)) 

注意,方案是1口齒不清(函數和變量相同的命名空間),而SBCL,像所有Common Lisp的實現,是一個2-lisp(函數和變量的不同名稱空間)。

因此在方案(define foo 3)定義爲恆定,同時(define foo (lambda() 3))定義常數函數。在Common Lisp的one way定義常量是

(defconstant foo 3) 
+0

供應我的權利從內存的工作。 '()'表示該函數不帶參數。 –

+0

解決!導致我使用** sbcl **,但寫計劃代碼,:P,謝謝, –

+0

是的,我認爲你會_intended_將該計劃翻譯成Common Lisp!很高興我能幫助,至少。 –