From: ··········@gmail.com
Subject: symbol-value in SBCL (corrected from earlier post)
Date: 
Message-ID: <ad796094-8355-44bf-b2c0-b4c77b3ff262@p25g2000hsf.googlegroups.com>
I've found something that seemed odd to me, about symbol-value 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: Scott Burson
Subject: Re: symbol-value in SBCL (corrected from earlier post)
Date: 
Message-ID: <83f65d84-f07b-4104-89cf-a75cebb1f87f@t12g2000prg.googlegroups.com>
On Apr 18, 7:03 am, ··········@gmail.com wrote:
> I've found something that seemed odd to me, about symbol-value 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)?

(Assuming you meant `symbol-value' rather than `symbol-function'.)

In CL, `symbol-value' can access the values only of dynamic (special)
variables.  It cannot access the value of a lexical variable (see the
CLHS entry for `symbol-value').

You expect this to work because Emacs-Lisp doesn't have lexical
variables -- they're all dynamic.  But in CL they're lexical by
default.

-- Scott
From: Pascal J. Bourguignon
Subject: Re: symbol-value in SBCL (corrected from earlier post)
Date: 
Message-ID: <7cr6d3w8xp.fsf@pbourguignon.anevia.com>
··········@gmail.com writes:

> I've found something that seemed odd to me, about symbol-value 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)

You still have symbol-function here ;-)

> 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

Otherwise, the answer doesn't change.

-- 
__Pascal Bourguignon__
From: Kent M Pitman
Subject: Re: symbol-value in SBCL (corrected from earlier post)
Date: 
Message-ID: <uod86q1og.fsf@nhplace.com>
··········@gmail.com writes:

> I've found something that seemed odd to me, about symbol-value 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)?

Some CL implementations don't allow you to do what you wrote, that is,
to assign a variable at toplevel unless you've defined it with defvar
(which changes everything and is not treated by the text I've written
in this post).

To portably do the experiment I assume you're trying, you need to do
 (setf (symbol-value 'foo) 12)
at the start to make it work, but CL's LET creates a lexical binding,
not a dynamic one.  SYMBOL-VALUE accesses the dynamic function binding,
not any lexical one.

> 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.

Heh.  SYMBOL-VALUE, I assume you mean.  (SYMBOL-FUNCTION is the global
function binding, and there is nothing that binds that; there are FLET
and LABELS, which each make lexical function bindings.  But there is
no dynamic variant.)

Btw, you _would_ get the same result if you had done:
 (let ((foo 42))
   (declare (special foo))
   (list foo (symbol-value 'foo)))

But no, it has nothing to do with deep vs shallow binding, which are
implementation strategies.  This is about lexical vs special.
From: ··········@gmail.com
Subject: Re: symbol-value in SBCL (corrected from earlier post)
Date: 
Message-ID: <dbd96b7b-ee96-4477-ad1d-51bc16451f17@d1g2000hsg.googlegroups.com>
Thanks, everyone, that explains it well... and yes, I meant symbol-
value, not symbol-function

__John