From: 勇勇 <zho...@ya...> - 2008-03-23 00:40:56
|
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? --------------------------------- 雅虎邮箱传递新年祝福,个性贺卡送亲朋! |
From: Nicolas N. <ne...@ma...> - 2008-03-24 08:37:29
|
勇勇 <zho...@ya...> writes: > ; 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? "Catching a condition" is standard terminology. You might look at the corresponding sections in the Hyperspec or Kent Pitman's condition paper: http://www.nhplace.com/kent/Papers/Condition-Handling-2001.html Nicolas |
From: Lars R. N. <lar...@gm...> - 2008-03-24 11:21:31
|
On Sun, 23 Mar 2008 08:40:39 +0800, 勇勇 wrote: > 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? Think about the name "SETF". It assigns a value to something. This "something" should be something it has seen before, or something you have declared before it. CL-USER> (defparameter *a*) *A* CL-USER> (setf *a* "dave") "dave" CL-USER> *a* "dave" CL-USER> (let ((a nil)) (setf a "dave") a) "dave" CL-USER> ..this way, you can be sure that you are only working with things you have "declared that you want to exist". Take this for instance: CL-USER> (let ((a nil)) (setf a "dave") (setf *b* "huh?")) ; in: LAMBDA NIL ; (SETF *B* "huh?") ; ==> ; (SETQ *B* "huh?") ; ; caught WARNING: ; undefined variable: *B* ; ; caught WARNING: ; This variable is undefined: ; *B* ; ; compilation unit finished ; caught 2 WARNING conditions "huh?" CL-USER> *b* "huh?" Suddenly *B* has popped up in the global environment without you having declared that it should exist (there). ...messy... -- Lars Rune Nøstdal http://nostdal.org/ |
From: Pascal B. <pj...@in...> - 2008-03-24 23:50:52
|
勇勇 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." |