勇勇 writes:
> hi,everyone:
>
> i am new to sbcl and lisp! when i use "setq" to define something in emacs(slime+sbcl)
> SLIME 2006-04-20
> CL-USER> (setq a "dave")
>
> ; in: LAMBDA NIL
> ; (SETQ A "dave")
> ;
> ; caught WARNING:
> ; undefined variable: A
>
> ;
> ; caught WARNING:
> ; This variable is undefined:
> ; A
> ;
> ; compilation unit finished
> ; caught 2 WARNING conditions
> "dave"
> CL-USER>
>
> it sucess to define a ,but why it displays "caught WARNING" ? do i do something wrong?
Yes, you did something wrong: you tried to assign an undefined variable.
The CL standard doesn't define what should happen when you assign a
variable that has not be defined. It leaves it up to the
implementation, and each implementation may do something different.
You can define a lexical variable with LET:
(let (a)
(setq a "dave")
(print a)
(values))
but of course, the variable A won't be defined outside of it's lexical
scope.
Or you can define a global dynamic variable with DEFVAR or DEFPARAMETER:
(defvar *a*)
(setq *a* "dave")
(print *a*)
But there is no way provided by CL to define a global lexical
variable. (It's possible to get something having the same effects
than a global lexical variable with symbol macros).
Note that since dynamic varibles are special, there is this convention
to name them surrounded by stars. The problem is that once you've
declared a variable special (dynamic), any use of that variable will
be special:
(defvar s 0)
(defun f ()
(print (list 'f '--> 's '= s))
(values))
(defun g ()
(let ((s 1))
(f)
(values)))
(g) prints:
(F --> S = 1)
--
__Pascal Bourguignon__ http://www.informatimago.com/
"Debugging? Klingons do not debug! Our software does not coddle the
weak."
|