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

eval-when issues



    Date: 16 July 1987, 10:12:53 EDT
    From: Timothy Daly <DALY at ibm.com>
    Re:   pathnames, portability, ed, eval-when, compile-file, fasl files

    [...]
    Second question:

    Is there any *portable* way I can tell whether a macro is being
    expanded in the compile time environment or the top level
    command environment?

Probably the answer is no.  A macro can do different things in these
circumstances using EVAL-WHEN, of course.  Moving on out over thin
ice, I would argue that a program that needs this information is
broken, is in error, is not Common Lisp.  The problem is that concepts
such as "at compile time" are very hard to pin down given the wide
range of legal Common Lisp implementation strategies such as "compile
only", "interpret only", and all kinds of hybrid/incremental
compilation schemes.

    That is, I need to set up certain compile time information for
    macros. These macros perform two functions. They generate
    forms for the compiler to compile into the file and they
    set up top level environment information. If they are expanded
    from compile-file in the compile-time environment, they modify
    the global state. If they are expanded at the top level they
    create and return forms that modify the global state redundantly.
    Truly tedious programming gets around this problem but one of two
    possible modifications to common lisp would solve *my* problem.

It's hard to tell what you are trying to do, but sounds like you are
writing your macros wrong.  Macroexpansion should never have
side-effects.  You should get your "compile time" side-effects by
using EVAL-WHEN.  If you put the stuff in an EVAL-WHEN (COMPILE LOAD EVAL),
then it will happen both at compile and load time, but only once when
interpreted at top-level.

    First, export the state used by EVAL-WHEN so I can use it (eval-when
    does not seem to be available except at the top level, thus I have
    to hack a compiler:phase-1-hook property which is beyond my cutoff
    point for hacking this week).

EVAL-WHEN (or equivalent) should work anywhere.  The concept of
"top-level form" doesn't belong in Common Lisp.  This is currently an
area of major lossage in the spec.  I have a compiler cleanup proposal
that replaces eval-when and banishes top-level forms.  This proposal
is supposedly being considered by the compiler cleanup committee.

    The second modification would be to allow me to write into a fasl
    file without using compile-file. That is,

    (compile 'foo :output-file pathname :if-exists :append)

Gag my with a spoon!  Hunh-uh...  No way!  fat chance, over my bloated
corpse. 

  Rob