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

Issue: LOAD-TIME-EVAL (Version 6)

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).


 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

 Clarify that #,exp as a form is an error and that load-time constants
 can only be used inside the QUOTE special form.


   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.


   It would be possible for macros to expand into load time constants.


;; 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)
		   ',(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.