[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Issue: LET-TOP-LEVEL (version 1)
- To: cl-cleanup%sail.stanford.edu@multimax
- Subject: Issue: LET-TOP-LEVEL (version 1)
- From: Dan L. Pierson <pierson@mist>
- Date: Tue, 01 Mar 88 16:02:35 EST
References: Top-Level Forms (p. 66), DEFUN (p. 67),
DEFVAR, DEFPARAMETER, DEFCONSTANT (pp. 68-69)
Edit history: Version 1 by Pierson 3/1/88
Status: For Internal Discussion
The main defining forms in CLtL do not support defining (as opposed to
creating) closures in lexical environments.
Require implementations to support DEFUN, DEFVAR, DEFPARAMETER, and
DEFCONSTANT enclosed in a LET at top level as well as a PROGN at top
level. Do not require support for DEFMACRO (environment irrelevant)
or EVAL-WHEN. Explicitly note that a "top level" let can be included
in a top level PROGN.
The following creates a simple resource allocation package for THINGs.
It needs to be COMPILE-FILEd to test it.
(LET ((THINGS '()))
(DEFUN GET-THING ()
(PROG1 (CAR THINGS)
(SETF THINGS (CDR THINGS)))
(DEFUN FREE-THING (THING)
(SETF THINGS (CONS THING THINGS))))
Common Lisp tries to support lexical closures but this support is
really confined to anonymous lambdas within other function
definitions. This proposal attempts to move lexical closures closer
to first-class status in Common Lisp.
The above example works in both Ibuki Lisp and Lucid, however only
Ibuki Lisp describes (SYMBOL-FUNCTION 'GET-THING) as a closure. Both
Symbolics and TI are reported to leave GET-THING and FREE-THING as
named-lambdas instead of compiling them.
Cost to Implementors:
While there is obviously some work required, it shouldn't be too hard
since all Common Lisp compilers are required to understand functions
in lexical closures in other contexts.
Cost to Users:
None, this is an upward compatible change.
Cost of non-Adoption:
Common Lisp will continue to leave a major style of lexical closure
use unsupported. This is probably most important to people converting
from Scheme to Common Lisp.
Lexical closures will become more useful. The increased information
hiding available may make some programs more maintainable by reducing
the number of global variables which really should be private to a
small group of functions. It will be easier to migrate some Scheme
programming styles to Common Lisp.
The aesthetics of the language will be improved by supporting a more
uniform view and use of lexical closures.
It has been pointed out that much of this proposal can be accomplished
by layering macros on top of SETF of SYMBOL-FUNCTION. The problem
with the macro approach is that it doesn't support whatever additional
environmental things the implementation may decide to do with DEFUN
(e.g. make an entry in the cross reference database).
One disadvantage of this proposal is that it doesn't interact well
with Lisp-style incremental development, for example a new top-level
defun of GET-THING wouldn't work. Pierson believes that this is an
inherent consequence of heavy use of lexical closures and that the
best workaround is to use an inspector which can support incremental
development within the current lexical scope, however this is all
outside the purvue of this committee.
Maybe this should be a compiler proposal instead of a cleanup proposal.