Subject: Re: FAQ 7.17: How can I access a dynamic variable while a similarly named lexical is in scope?
From: rpw3@rigden.engr.sgi.com (Rob Warnock)
Date: 1999/07/17
Newsgroups: comp.lang.lisp
Message-ID: <7mplj7$pfcu@fido.engr.sgi.com>
David Bakhash  <cadet@bu.edu> 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.
	3
	* (let ((x 4))
	    (list x (symbol-value 'x)))
	(4 4)
	* x
	3
	* 

(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)
	3
	* (let ((y 4)) 
	    (list y (symbol-value 'y)))
	(4 3)
	* y
	3
	* 

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

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