Subject: Re: More Scope...
From: Erik Naggum <erik@naggum.no>
Date: 2000/02/25
Newsgroups: comp.lang.lisp
Message-ID: <3160482077049507@naggum.no>

* Keke Abe
| Could you explain the distinction?  I've read the 1996 thread but could
| not figure that out.

  a binding of a lexical variable is an entirely new variable, one that may
  be captured independently of any other variable, and which is not visible
  anywhere else.  a binding of a special variable is a dynamic association
  between variable and value which is seen everywhere else the same
  variable is referenced.  the reference to a lexical variable is under the
  supreme control of the compiler, which may allocate it to a register or
  to a stack frame, and which will typically discard the symbol association.
  the reference to a special variable is like a call to symbol-value on
  that symbol.

  this means that the statement "there may be a lexical and dynamic
  variable with the same name" is terribly confused.  yes, it is possible
  to "forget" to declare a symbol special, which means any binding will be
  lexical, but so, then, will any normal reference.  in order to access the
  symbol, you can no longer just name it, you need to call symbol-value or
  set when you want to read or change its value.  but at this time, we're
  clearly doing something very different than what we did with variables --
  we're actually tinkering with the underlying implementation of special
  variables.

  a fully true statement would be that the symbol-value slot of a symbol is
  accessible and may be accessed also when the symbol has not been declared
  special.  however, using a variable means _not_ having to do anything
  special like that at every access, so it's clear that we access a
  symbol's internal information in code like this:

(1) common-lisp-user
;; In Lisp Listener #2
(2) common-lisp-user
(defun foobar (x)
  (values x (symbol-value 'x)))
=> foobar
(3) common-lisp-user
(setq x 666)
=> 666
(4) common-lisp-user
(foobar 4711)
=> 4711
=> 666
(5) common-lisp-user
(defvar x 69)
=> x
(6) common-lisp-user
(foobar 4711)
=> 4711
=> 4711
(7) common-lisp-user

  hope this helps.

#:Erik