[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
- To: Kent M Pitman <KMP@scrc-stony-brook.arpa>, Gray%dsg.csc.ti.com@NSS.Cs.Ucl.AC.UK
- Subject: Re: LOAD-TIME-EVAL
- From: Jeff Dalton <jeff%aiai.edinburgh.ac.uk@NSS.Cs.Ucl.AC.UK>
- Date: Fri, 9 Sep 88 15:14:53 BST
- Cc: sandra <@cs.utah.edu:sandra@defun>, Cl-Compiler@sail.stanford.edu
> (DEFVAR I-HOPE-THIS-IS-UNIQUE-0001 (+ (FORTRAN-VARIABLE-OFFSET 'FOO 'X) 3))
> (DEFVAR I-HOPE-THIS-IS-UNIQUE-0002 (FORTRAN-VARIABLE-OFFSET 'FOO 'Y))
> ... (+ (AREF *FORTRAN-VIRTUAL-MEMORY*
> (+ I-HOPE-THIS-IS-UNIQUE-0001
> (AREF *FORTRAN-VIRTUAL-MEMORY* I-HOPE-THIS-IS-UNIQUE-0002)))
> 2) ...
> Anyone who asks that #, be flushed is, in effect, asking me to write
> this kind of stuff. Among other things, it forces the creation of
> numerous extra symbols and it may require an indirect access to the
> value (through the symbol's value cell) in some implementations where
> an immediate move (or even an instruction that utilizes a constant
> operand) might have been possible if quote were used.
Although I agree with Kent's point that load-time eval is useful and
better than many of the alternatives (especially since some of the
alternatives don't quite work), the "I hope this is unique" problem
can often be reduced.
In some other languages I can use static variables
static int initialized = FALSE;
static int v1, v2, ...;
v1 = ...;
v2 = ...;
... procedure body code ...
This is not ideal, of course.
Similar tricks can be done in Lisp (I think) by generating global
(defmacro eval-once (form)
(let ((v (gensym)))
`(locally (declare (special ,v))
(if (boundp ',v) ;initialized?
(setq ,v ,form)))))