home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / lang / lisp / 2206 < prev    next >
Encoding:
Text File  |  1992-08-12  |  1.9 KB  |  51 lines

  1. Path: sparky!uunet!sun-barr!cs.utexas.edu!usc!rpi!think.com!barmar
  2. From: barmar@think.com (Barry Margolin)
  3. Newsgroups: comp.lang.lisp
  4. Subject: Re: Weird lucid behaviour: calling macros inside files at top level
  5. Date: 13 Aug 1992 08:56:51 GMT
  6. Organization: Thinking Machines Corporation, Cambridge MA, USA
  7. Lines: 38
  8. Message-ID: <16d84jINNltb@early-bird.think.com>
  9. References: <1992Aug11.203152.26760@cs.cornell.edu> <16a9a7INNq3@early-bird.think.com> <1992Aug12.123449.5482@cs.cornell.edu>
  10. NNTP-Posting-Host: gandalf.think.com
  11. Keywords: macros, automatic defstructs
  12.  
  13. In article <1992Aug12.123449.5482@cs.cornell.edu> raman@cs.cornell.edu (T. V. Raman) writes:
  14. >barmar@think.com (Barry Margolin) writes:
  15. >>I suspect your problem is that you aren't assigning the list to the
  16. >>variable at compile time (i.e. with (EVAL-WHEN (COMPILE) ...)), or you're
  17. >>side effecting a constant.
  18. >
  19. >I suspect that the reason is the above. I have never used eval-when
  20. >and in my code I simply have
  21. >
  22. >(defvar *list-of-dimensions* ...)
  23. >
  24. >and some calls at top level in the file that push items on to this
  25. >list using
  26. >(push item *list-of-dimensions*)
  27.  
  28. The problem is that ordinary forms are executed only when the file is
  29. loaded.  Thus, the PUSH won't happen until then.  However, macros are
  30. expanded by the compiler.  So if you have a macro that expands into a
  31. DEFSTRUCT, and it wants to use a global variable in computing the
  32. expansion, then you must make sure that this variable has been assigned
  33. before the macro is expanded.
  34.  
  35. You can do this in two ways.  One is to load the file that contains the
  36. DEFVAR and PUSHes before compiling anything that uses the macro.
  37.  
  38. But if you want to use the macro in the same file as those forms appear,
  39. you have to use EVAL-WHEN to force them to execute during the compilation
  40. of the file.
  41.  
  42. (eval-when (compile load eval)
  43.   (defvar ...)
  44.   (push ...)
  45.   ...)
  46. -- 
  47. Barry Margolin
  48. System Manager, Thinking Machines Corp.
  49.  
  50. barmar@think.com          {uunet,harvard}!think!barmar
  51.