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

Another omission: global lexicals

    It is truly silly that there is no way to define a global lexical
variable in Common Lisp.  Many places where defvar is used there is no
need for dynamic binding, since the variable is never bound.  If a
variable is known to be a global lexical then various optimizations
can be made which are otherwise impossible:
 1] A global lexical cannot be unbound, therefore there is no need to
    check that is bound before accessing it.
 2] Since it cannot be globally rebound, there is no need to search
    for the value in an implementation which deep-binds specials.
    This is significant since shallow-binding doesn't work in
    multi-processor implementations.

    A global lexical is also less dangerous to use than a global
special, since a global lexical doesn't magically specialify other
lexical uses of the same name.  Dynamic binding is overkill in many
applications.  I believe that programs would be clearer if it was more
obvious which variables are actually bound dynamically.

    It is also worth noting that it should be trivial to add global
lexicals to any implementation.  The value is kept in the global value
cell, just as for a special; the only difference is that there is no
special annotation.

    I suggest this syntax:  DEFGLOBAL <name> <value> [<doc-string>]