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

Re: LOAD-TIME-EVAL



>  (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 

    int f()
    {
        static int initialized = FALSE;
        static int v1, v2, ...;
        if not(initialized)
        {
            v1 = ...;
            v2 = ...;
            ...;
        }
        ... procedure body code ...
    }

This is not ideal, of course.

Similar tricks can be done in Lisp (I think) by generating global
variables:

(defmacro eval-once (form)
  (let ((v (gensym)))
    `(locally (declare (special ,v))
       (if (boundp ',v)			;initialized?
           ,v
         (setq ,v ,form)))))