Subject: Re: FAQ 7.17: How can I access a dynamic variable while a similarly named lexical is in scope?
From: (Rob Warnock)
Date: 1999/07/17
Newsgroups: comp.lang.lisp
Message-ID: <7mplj7$>
David Bakhash  <> wrote:
| So I gave it a shot, and was surprised by what I saw:
| CL-USER 1 > (setq x 3)
| 3
| CL-USER 2 > (let ((x 4))
|               (list x (symbol-value 'x)))
| (4 3)
| ;; okay.  So that's good.  That's what I wanted to see.

Well, don't start depending on that.  There's no defined way in the
Common Lisp standard to have a global lexical variable. Yes, CLISP
and maybe some other Lisps give the above behavior, but CMUCL, for
example, gives this:

	* (setq x 3)
	Warning:  Declaring X special.
	* (let ((x 4))
	    (list x (symbol-value 'x)))
	(4 4)
	* x

(At least CMUCL prints a warning.)

However, CMUCL has its quirks in this area, too, I think. Suppose you
never set the "variable", only the "symbol"?  Then it looks like you
can get a sort of "global lexical":

	* (setf (symbol-value 'y) 3)   ; instead of (setf y 3)
	* (let ((y 4)) 
	    (list y (symbol-value 'y)))
	(4 3)
	* y

So what's wrong with this? Maybe nothing, but... The HyperSpec says that
the argument to "symbol-value" (even in the "stef" form) must already have
a value. But at the same time, it says:

	Should signal "unbound-variable" if symbol is unbound and an attempt
	is made to read its value. (No such error is signaled on an attempt
	to write its value.) 

Now, for the "unbound" case, does "no error is signaled on...write" mean
that the write is guaranteed to succeed, or that it *may* fail but that
no error is signalled? Without some clarification, I don't see that the
behavior can be counted on.


Rob Warnock, 8L-855
Applied Networking
Silicon Graphics, Inc.		Phone: 650-933-1673
1600 Amphitheatre Pkwy.		FAX: 650-933-0511
Mountain View, CA  94043	PP-ASEL-IA