Subject: Re: toplevel variables in CMUCL, get rid of the SPECIAL declaration!
From: rpw3@rigden.engr.sgi.com (Rob Warnock)
Date: 13 Jan 2001 14:18:19 GMT
Newsgroups: comp.lang.lisp
Message-ID: <93po3b$nijjl$1@fido.engr.sgi.com>
Barry Margolin  <barmar@genuity.net> wrote:
+---------------
|  <joswig@corporate-world.lisp.de> wrote:
| >I just want:
| >- that global variables are not necessarily declared special
| 
| Sorry, Common Lisp doesn't have global, non-special variables.  CLTL2 says
| that if a variable reference occurs outside a construct that creates a
| lexical binding, it's taken to refer to the special variable.  I can't find
| the analogous statement in the standard, but I expect it's in there
| someplace.
+---------------

Well, the CLHS glossary says:

	global variable n. a dynamic variable or a constant variable.

	lexical variable n. a variable the binding for which is in the
	    lexical environment. 

	lexical environment n. that part of the environment that contains
	    bindings whose names have lexical scope.

That's a big hint, but I think this[*] nails it:

	3.1.2.1.1 Symbols as Forms
	If a form is a symbol, then it is either a symbol macro or a variable.
	...
	If a form is a symbol that is not a symbol macro, then it is the
	name of a variable, and the value of that variable is returned.
[*]==>	There are three kinds of variables: lexical variables, dynamic
	variables, and constant variables.

So if a variable *ever* exists when it's not lexically bound, then it's
either dynamic (special) or constant. And once special, always special,
even when subsequently bound. I take that as saying that all (non-constant)
globals are special.


-Rob

p.s. Are constant variables special?  Well, it doesn't matter whether
they are or not, since binding one isn't allowed. "3.1.2.1.1.3 Constant
Variables" says:

	The consequences are undefined if an attempt is made to assign a
	value to, or create a binding for a constant variable...

and "Macro DEFCONSTANT" says:

	The consequences are undefined when constant symbols are rebound as
	either lexical or dynamic variables. In other words, a reference to
	a symbol declared with defconstant always refers to its global value.

and issue "DEFCONSTANT-SPECIAL:NO" ("DEFCONSTANT-SPECIAL:DOESNT-MATTER",
as passed) says it even more strongly:

	Clarify that it is an error to rebind constant symbols as either
	lexical or special variables.  (In other words, a reference to a
	symbol declared with DEFCONSTANT always refers to its global value.)

-----
Rob Warnock, 31-2-510		rpw3@sgi.com
SGI Network Engineering		http://reality.sgi.com/rpw3/
1600 Amphitheatre Pkwy.		Phone: 650-933-1673
Mountain View, CA  94043	PP-ASEL-IA