guile-devel
[Top][All Lists]
Advanced

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

Re: When should eval-when eval?


From: Rob Browning
Subject: Re: When should eval-when eval?
Date: 16 May 2001 10:13:22 -0500
User-agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/20.7

Marius Vollmer <address@hidden> writes:

> Rob Browning <address@hidden> writes:
> 
> > My assumption would be
> > 
> >   compile - forms are executed when the code is compiling.
>               and the eval-when form is on top-level
> 
> >   load - forms are executed when the shared library is loaded.
>            and the eval-when form is on top-level
> 
> >   eval - forms are executed when the code is actually executed.
>            and the eval-when form is not on top-level

OK, so eval-when only works on the top level in Guile.  OK.  I kinda
expected that, and it simplifies things.  That's not the case in CL.

> No, no, and yes.

What's the difference between load time and eval time for a top-level
form?  Is there one?

> Yes, I think we should follow Common Lisp in this regard.

Well, on the eval-when front at least, CL specifies a whole case table
outlining the actions taken for all the combinations of the
situational keywords :compile-toplevel, :load-toplevel, and :execute,
depending on whether or not you're in "not-compile-time" mode or
"compile-time-too" mode (which I have yet to figure out the precise
difference between).

And in their case, the :compile-toplevel and :load-toplevel keyword
control when top-level forms are processed, and the :execute keyword
controls whether processing should be done for non-top-level-forms.

I wondered why you'd ever put an eval-when in a non-top-level form,
but it just dawned on me that it might be relevant for
macroexpansions.  i.e.

  (define-macro (foo)
    `(eval-when (:compile-toplevel :load-toplevel :execute)
      ...))

would expand into ... always, at the top-level, and if it were (as the
result of an expansion) in the body of another form, whereas:

  (define-macro (foo)
    `(eval-when (:compile-toplevel :load-toplevel)
      ...))

would expand only when it occurred at the top level.

So I'm wondering if that's how our "eval" situation should be
interpreted.

They also explicitly consider macros having side-effects that are
performed by the macroexpander.  They say:

  (defmacro foo ()
    (really-foo)
    `(really-foo))

is "Wrong", and this is right:

  (defmacro foo ()
    `(eval-when (:compile-toplevel :load-toplevel :execute)
       (really-foo)))

They argue that following this convention makes sure that macros will
behave intuitively when called in non-top-level positions.

I'll also try to look at the compilation chapter for other interesting
bits.

Thanks

-- 
Rob Browning <address@hidden> PGP=E80E0D04F521A094 532B97F5D64E3930



reply via email to

[Prev in Thread] Current Thread [Next in Thread]