From: ··········@gmail.com
Subject: symbol-function in SBCL
Date: 
Message-ID: <ee0eab5b-c09f-4a34-a063-688482ba71a6@c65g2000hsa.googlegroups.com>
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: Pascal J. Bourguignon
Subject: Re: symbol-function in SBCL
Date: 
Message-ID: <7cfxtjxt5k.fsf@pbourguignon.anevia.com>
··········@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: ··········@gmail.com
Subject: Re: symbol-function in SBCL
Date: 
Message-ID: <f194b052-e719-4954-9b7b-a95f66547bda@e53g2000hsa.googlegroups.com>
Thanks, that clarifies it! and of course, I meant symbol-value (I
think I was thinking "the function symbol-value", or something like
that).
From: Alex Mizrahi
Subject: Re: symbol-function in SBCL
Date: 
Message-ID: <48088e40$0$90262$14726298@news.sunsite.dk>
 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.