[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Issue: LOAD-TIME-EVAL (Version 6)
- To: Kent M Pitman <KMP@STONY-BROOK.SCRC.Symbolics.COM>, Gregor.pa@Xerox.COM, Patrick Dussud <dussud@lucid.com>, Sandra J Loosemore <sandra%defun@cs.utah.edu>, Eric Benson <eb@lucid.com>
- Subject: Issue: LOAD-TIME-EVAL (Version 6)
- From: David A. Moon <Moon@STONY-BROOK.SCRC.Symbolics.COM>
- Date: Wed, 21 Sep 88 14:50 EDT
- Cc: CL-Cleanup@SAIL.STANFORD.EDU, cl-compiler@sail.stanford.edu
- In-reply-to: <880608165454.0.KMP@PEWEE.SCRC.Symbolics.COM>, <19880921012425.2.GREGOR@PORTNOY.parc.xerox.com>, <8809210256.AA19086@rainbow-warrior>, <8809210424.AA00814@defun.utah.edu>, <8809210622.AA01147@blacksox>
- Line-fold: No
For the purposes of discussion, here's a copy of KMP's last writeup
stripped down to just what I personally think are the essentials.
I don't mean to supersede Kent's writeup, just to give people
something short enough to read. Kent's writeup also included
the new-special-form version and compared and constrasted the
two versions.
Issue: LOAD-TIME-EVAL
References: #, (p. 356), (EVAL-WHEN (LOAD) ...) (p. 69-70)
Category: ADDITION
Edit history: 06-Jun-87, Version 1 by James Kempf
17-Jul-87, Version 2 by James Kempf
12-Nov-87, Version 3 by Pitman (alternate direction)
01-Feb-88, Version 4 by Moon
(from version 2 w/ edits suggested by Masinter)
06-Jun-88, Version 5 by Pitman
(fairly major overhaul, merging versions 3 and 4)
21-Sep-88, Version 6 by Moon (stripped down)
Status: For internal discussion
Problem description:
Common Lisp provides reader syntax (#,) which allows the programmer
to designate that a particular expression within a program is to be
evaluated early (at load time) but to later be treated as a constant.
Unfortunately, no access to this capability is available to programs
which construct other programs without going through the reader.
Some computations can be deferred until load time by use of EVAL-WHEN,
but since EVAL-WHEN must occur only at toplevel, and since the nesting
behavior of EVAL-WHEN is quite unintuitive, EVAL-WHEN is not a general
solution to the problem of load-time computation of program constants.
Also, CLtL is vague about the meaning of #,exp as a form (rather than
inside a quoted constant).
Proposal (LOAD-TIME-EVAL:QUOTED-MAGIC-TOKEN):
Add a function MAKE-LOAD-TIME-CONSTANT, as described here:
MAKE-LOAD-TIME-CONSTANT form env [Function]
FORM is a Lisp form. ENV is an environment of the sort received
by the &ENVIRONMENT argument to a macro.
When MAKE-LOAD-TIME-CONSTANT is called from the interpreter or the
COMPILE function, it simply evaluates FORM in the null lexical
environment and returns its value. When MAKE-LOAD-TIME-CONSTANT is
called during a file compilation, the result is a special object
that is recognized at load time, when it occurs inside a constant.
At load time, FORM is evaluated and its value is substituted for
the object.
MAKE-LOAD-TIME-CONSTANT uses its ENV argument to determine whether it
is being called during a file compilation.
Specify that '(... #,exp ...) is equivalent to
'(... #.(MAKE-LOAD-TIME-CONSTANT 'exp env) ...)
with the "right" value of env.
Specify that anything Common Lisp says about destructive operations
on constants also applies to values returned by forms used as
arguments to MAKE-LOAD-TIME-CONSTANT.
Clarify that #,exp as a form is an error and that load-time constants
can only be used inside the QUOTE special form.
Rationale:
This approach is the most compatible with existing practice.
Cost to Implementors:
The cost to implementors will depend on how #, is implemented.
In some implementations, the primitives for implementing
MAKE-LOAD-TIME-CONSTANT may already exist, in others, more substantial
changes may be required.
Cost to Users:
This change is upward compatible with user code.
Benefits:
It would be possible for macros to expand into load time constants.
Example:
;; This is a stripped down version of something from CLOS
(defmacro deffoo (name attribute &environment e)
`(defun ,name (x)
(aref x (aref ',(make-load-time-constant
`(get-table-for ',attribute)
e)
',(get-index-for ',attribute)))))
Current practice:
Although most implementations provide a substrate which would allow
program-mediated access to load time evaluation in some way, the language
only defines access to this substrate through the sharpsign read syntax.