开发者

The variable B is unbound in Lisp

开发者 https://www.devze.com 2023-04-06 10:30 出处:网络
sorry for my poor english:) I have a problem with lisp. i type code here http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-10.html to sbcl

sorry for my poor english:) I have a problem with lisp. i type code here http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-10.html to sbcl

* (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.
开发者_开发技巧

some one give me a help?


You define a function with DEFUN:

(defun a () 3)

In your case you're trying to call the function DEFINE with an argument A... which is of course undefined.

More generally, you supply the parameters to a function like this:

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

Note that Scheme is a 1-lisp (same namespace for functions and variables) while SBCL, like all Common Lisp implementations, is a 2-lisp (different namespaces for functions and variables).

Thus in Scheme (define foo 3) defines a constant while (define foo (lambda () 3)) defines a constant function. In Common Lisp one way to define a constant is

(defconstant foo 3)
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号