home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!gumby!wupost!sdd.hp.com!think.com!barmar
- From: barmar@think.com (Barry Margolin)
- Newsgroups: comp.lang.lisp
- Subject: Re: Macros, macroexpansion & the compile-time environment.
- Date: 2 Sep 1992 17:09:25 GMT
- Organization: Thinking Machines Corporation, Cambridge MA, USA
- Lines: 44
- Message-ID: <182sg5INN3sc@early-bird.think.com>
- References: <22303@venera.isi.edu>
- NNTP-Posting-Host: telecaster.think.com
-
- In article <22303@venera.isi.edu> tar@isi.edu writes:
- > (defmacro if (test then &rest else-list)
- > (when (null else-list)
- > (warn "IF statements should have an else clause"))
- > `(COMMON-LISP:if ,test ,then ,@else-list))
-
- Shouldn't that be
-
- `(COMMON-LISP:if ,test ,then (progn ,@else-list))
-
- > (defmacro other-macro (&rest body-of-macro)
- > ;; We do some processing of the body, gory details omitted.
- > (dolist (form body-of-macro)
- > (if (test-form form) ;; <==== NOTE the "IF" here
- > (do-this form)
- > (do-that form)))
- > `(some-function ,@args))
-
- > Does the CommonLisp standard require the shadowed definition of
- > "IF" to be used in "OTHER-MACRO"? Or is the standard mute?
-
- The dpANS makes it explicitly unspecified. The dpANS defines two relevant
- environments in sec.3.2.1: The "compilation environment", which is where
- the compiler temporarily remembers things that it needs to know to compile
- later forms in the same file; and the "evaluation environment", which is
- where macro expanders and (eval-when (compile) ...) code are executed. It
- then says, "It is unspecified whehter a definition available in the
- compilation environment can be used in an evaluation initiated in the
- startup environment or evaluation environment." (The reference to the
- startup environment doesn't affect the above case.) A similar statement
- appears in sec.3.2.3.1.1 "Processing of Defining Macros". This makes both
- implementations valid, and the above program non-conforming because it
- depends on unspecified behavior.
-
- >P.S.: I know how to fix the problem for Allegro (use
- > "common-lisp:if"), I was just curious about the environment issue).
-
- Actually, you just need to put an (EVAL-WHEN (COMPILE LOAD EVAL) ...)
- around the IF macro definition.
- --
- Barry Margolin
- System Manager, Thinking Machines Corp.
-
- barmar@think.com {uunet,harvard}!think!barmar
-