|
Prev: Inserting into a list ?
Next: Brand Watches Gucci Men's 101 Series watch #YA101312 Discount, Replica, Fake
From: jcg.sturdy on 18 Apr 2008 07:40 I've found something that seemed odd to me, about symbol-function in SBCL: that it uses the global value rather than the same binding as the evaluator, so that (setq foo 12) (let ((foo 42)) (list foo (symbol-value 'foo))) yields (42 12) Now I'm rusty at CL (have mostly used EmacsLisp for the last 10 years or so) so I may just be misremembering, but I thought that x and (symbol-function 'x) should have the same result (as they do in EmacsLisp)? I expect this is something to do with deep binding and perhaps with threading, but I'm a bit surprised that symbol-function doesn't try to get the same result. __John
From: Alex Mizrahi on 18 Apr 2008 08:04 js> I've found something that seemed odd to me, about symbol-function in js> SBCL: that it uses the global value rather than the same binding as js> the evaluator, so that js> (setq foo 12) js> (let ((foo 42)) js> (list foo (symbol-value 'foo))) js> yields js> (42 12) basically, there are two types of variables -- lexical and special (or dynamic). if you do not specify which one you're using, weird things might happen. so, you need to introduce variables via defvar/defparameter or via let, but not just write SETQ. you can find more information here: http://www.flownet.com/ron/specials.pdf js> Now I'm rusty at CL (have mostly used EmacsLisp for the last 10 years js> or so) so I may just be misremembering, but I thought that js> x js> and js> (symbol-function 'x) symbol-FUNCTION? js> should have the same result (as they do in EmacsLisp)? iirc Emacs Lisp does not have lexical variables. Common Lisp is more modern and a bit complicated.
From: Pascal J. Bourguignon on 18 Apr 2008 08:08 jcg.sturdy(a)gmail.com writes: > I've found something that seemed odd to me, about symbol-function in > SBCL: that it uses the global value rather than the same binding as > the evaluator, so that > (setq foo 12) > (let ((foo 42)) > (list foo (symbol-value 'foo))) > yields > (42 12) > > Now I'm rusty at CL (have mostly used EmacsLisp for the last 10 years > or so) so I may just be misremembering, but I thought that > x > and > (symbol-function 'x) > should have the same result (as they do in EmacsLisp)? > > I expect this is something to do with deep binding and perhaps with > threading, but I'm a bit surprised that symbol-function doesn't try to > get the same result. Common Lisp has lexical bindings and dynamic binding. Emacs Lisp has only dynamic bindings. You could infer from that that there will be places where their behavior will differ. (setq foo 12) ; is not defined in Common Lisp (let ((foo 42)) (list foo (symbol-value 'foo))) Let's try something that's defined in Common Lisp: (defparameter *foo* 12) ; defines a dynamic variable named *foo*. (let ((foo 42)) ; binds a lexical variable named foo. (list foo (symbol-value '*foo*))) ; get their values. --> (42 12) (let ((foo 13)) ; defines a dynamic variable named foo (declare (special foo)) (let ((foo 42)) ; still binds a lexical variable named foo. (list foo (symbol-value 'foo)))) ; get their values. --> (42 13) (let ((foo 13)) ; defines a dynamic variable named foo (declare (special foo)) (let ((foo 42)) ; rebinds the same dynamic variable named foo (declare (special foo)) (list foo (symbol-value 'foo)))) ; get its value. --> (42 42) (let ((foo 13)) ; defines a dynamic variable named foo (declare (special foo)) (let ((foo 'lexical)) ; binds a lexical variable named foo. (let ((foo 42)) ; rebinds the same dynamic variable named foo (declare (special foo)) (list foo (symbol-value 'foo))))) ; get its value. --> (42 42) -- __Pascal Bourguignon__
From: jcg.sturdy on 24 Apr 2008 10:34
Thanks, that clarifies it! and of course, I meant symbol-value (I think I was thinking "the function symbol-value", or something like that). |