[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Issue: PROCLAIM-LEXICAL



I support PROCLAIM-LEXICAL:GENERAL if the implementation issues can
be worked out, which I think they can.

I spoke with Jonathan briefly about these problems and I think he
agrees with me that they're not really a problem if you just keep
the global lexical value cells someplace other than the SYMBOL-VALUE
of the symbol.

For example, you might write:

 (DEFVAR SYSTEM:*THE-GLOBAL-LEXICAL-VALUE-CELLS* (MAKE-HASH-TABLE))

 (DEFUN SYSTEM:GLOBAL-LEXICAL-VALUE-CELL (SYMBOL)
   (OR (GETHASH SYMBOL SYSTEM:*THE-GLOBAL-LEXICAL-VALUES-CELLS*)
       (SETF (GETHASH SYMBOL SYSTEM:*THE-GLOBAL-LEXICAL-VALUES-CELLS*)
	     (CONS SYMBOL ;For debugging
		   SYSTEM:*UNBOUND-MARKER*))))

 (DEFMACRO SYSTEM:GLOBAL-LEXICAL-VALUE (SYMBOL)
   `(CDR (EVALUATE-AT-LOAD-TIME (SYSTEM:GLOBAL-LEXICAL-VALUE-CELL ',SYMBOL))))

Of course (as stated above), this changes his proposal slightly to
make the global lexical and dynamic environments disjoint. That is,
programs like
 (DEFUN MAYBE-EVEN-BUT-SURELY-ODD ()
   (+ (LOCALLY (DECLARE (LEXICAL X) (INTEGER X)) X)
      (LOCALLY (DECLARE (SPECIAL X) (INTEGER X)) X)))
could return odd numbers (since lexical X and special X might denote
different quantities).

The contract of the compiler would be to turn global lexical
references to a symbol into (SYSTEM:GLOBAL-LEXICAL-VALUE 'symbol).
The call to SYSTEM:GLOBAL-LEXICAL-VALUE-CELL (ie, the GETHASH) need
happen only once (at load time) so its speed is not important.

If the above code wanted to be portable, of course, you'd have to have
an S-expression equivalent to #, called EVALUATE-AT-LOAD-TIME. Most
implementations have such a thing, I think, they just don't let it out
for users to play with. In fact, I think CL should have such a thing
since this isn't the first case where people have wanted it.
In any case, portability isn't relevant to this message since all
that's needed is to demonstrate that it would be feasible to implement
this in all systems, which I think the above code demonstrates.