ilan@lcuxlm.UUCP (02/09/88)
I imagine this subject has come up before - if so please excuse my laziness for not looking up back-messages. In spite of CLtL's disclaimer re EVAL-WHEN that "its uses are relatively esoteric" (p. 69) - it can be very useful. In particular, allowing macro references to be resolved at compile-time within a file that both defines and uses those macros. For instance, say file FOO.L contains: (DEFMACRO M1 (X Y) `(+ ,x ,y)) (DEFUN FOO (X Y) (M1 X Y)) When interpreted, i.e. via (LOAD "FOO.L") this has the obvious result of creating a function FOO that adds two lisp objects (hopefully numbers). The compiled version of this file "should produce an equivalent but more efficient program" (p. 438). This implies that at compile-time, upon encountering the reference to M1 within FOO, the compiler should already know that it's a macro. One way of doing this is to wrap the macro in an EVAL-WHEN (COMPILE LOAD). Another way is to somehow special-case DEFMACRO within COMPILE-FILE. For instance, implicitly evaluating the DEFMACRO when encountered at compile-time and then "undoing" that evaluation so that you don't get unwanted side-effects in your current lisp session. Several implementations choose the latter route: the TI explorer, Franz Common. This approach raises the following question: should not *all* top-level DEFs (DEFTYPE, DEFVAR, DEFPARAMETER etc.) be therefore special-cased by the compiler? If so, and assuming that your compiler is in Common Lisp itself (which I think is natural), you need a way of say, unPROCLAIMing variables... something that is impossible in CL. Well then, why not go for the EVAL-WHEN solution? In all of the systems I've seen (TI explorer, Kyoto Common Lisp, Franz Common Lisp, Xerox) I've yet to see an accurate implementation. The TI, Franz Common (I think they call it Allegro now), Xerox all complain about non-top-level EVAL-WHEN's. The TI says for instance that EVAL-WHEN within a function is "not meaningful". My questions are: (1) If one chooses to impose upon the poor programmer the need to explicitly wrap all his DEFMACROs in the appropriate EVAL-WHEN, then do the macros that got defined during the COMPILE-FILE remain extant once the compile finishes? (2) Is it meaningful to have embedded EVAL-WHENs? I would say that it is... I can think of non-artificial uses: for instance for debugging purposes you could trace compiler execution by inserting (EVAL-WHEN (COMPILE) ...) forms at strategic locations. --Ilan Caron 201-580-5664 ..allegra!lcuxlm!ilan -- Ilan Caron 201-580-5664 (w) 201-937-9158 (h) email: ..!allegra!lcuxlj!ilan