home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / lisp / 2360 < prev    next >
Encoding:
Internet Message Format  |  1992-09-02  |  2.3 KB

  1. Path: sparky!uunet!gumby!wupost!sdd.hp.com!think.com!barmar
  2. From: barmar@think.com (Barry Margolin)
  3. Newsgroups: comp.lang.lisp
  4. Subject: Re: Macros, macroexpansion & the compile-time environment.
  5. Date: 2 Sep 1992 17:09:25 GMT
  6. Organization: Thinking Machines Corporation, Cambridge MA, USA
  7. Lines: 44
  8. Message-ID: <182sg5INN3sc@early-bird.think.com>
  9. References: <22303@venera.isi.edu>
  10. NNTP-Posting-Host: telecaster.think.com
  11.  
  12. In article <22303@venera.isi.edu> tar@isi.edu writes:
  13. >  (defmacro if (test then &rest else-list)
  14. >     (when (null else-list)
  15. >       (warn "IF statements should have an else clause"))
  16. >     `(COMMON-LISP:if ,test ,then ,@else-list))
  17.  
  18. Shouldn't that be
  19.  
  20.   `(COMMON-LISP:if ,test ,then (progn ,@else-list))
  21.  
  22. >  (defmacro other-macro (&rest body-of-macro)
  23. >    ;; We do some processing of the body, gory details omitted.
  24. >    (dolist (form body-of-macro)
  25. >      (if (test-form form)        ;; <==== NOTE the "IF" here
  26. >      (do-this form)
  27. >          (do-that form)))
  28. >    `(some-function ,@args))
  29.  
  30. >    Does the CommonLisp standard require the shadowed definition of
  31. >    "IF" to be used in "OTHER-MACRO"?  Or is the standard mute?
  32.  
  33. The dpANS makes it explicitly unspecified.  The dpANS defines two relevant
  34. environments in sec.3.2.1: The "compilation environment", which is where
  35. the compiler temporarily remembers things that it needs to know to compile
  36. later forms in the same file; and the "evaluation environment", which is
  37. where macro expanders and (eval-when (compile) ...) code are executed.  It
  38. then says, "It is unspecified whehter a definition available in the
  39. compilation environment can be used in an evaluation initiated in the
  40. startup environment or evaluation environment."  (The reference to the
  41. startup environment doesn't affect the above case.)  A similar statement
  42. appears in sec.3.2.3.1.1 "Processing of Defining Macros".  This makes both
  43. implementations valid, and the above program non-conforming because it
  44. depends on unspecified behavior.
  45.  
  46. >P.S.:  I know how to fix the problem for Allegro (use
  47. >       "common-lisp:if"), I was just curious about the environment issue).
  48.  
  49. Actually, you just need to put an (EVAL-WHEN (COMPILE LOAD EVAL) ...)
  50. around the IF macro definition.
  51. -- 
  52. Barry Margolin
  53. System Manager, Thinking Machines Corp.
  54.  
  55. barmar@think.com          {uunet,harvard}!think!barmar
  56.