home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!sun-barr!cs.utexas.edu!usc!rpi!think.com!barmar
- From: barmar@think.com (Barry Margolin)
- Newsgroups: comp.lang.lisp
- Subject: Re: Weird lucid behaviour: calling macros inside files at top level
- Date: 13 Aug 1992 08:56:51 GMT
- Organization: Thinking Machines Corporation, Cambridge MA, USA
- Lines: 38
- Message-ID: <16d84jINNltb@early-bird.think.com>
- References: <1992Aug11.203152.26760@cs.cornell.edu> <16a9a7INNq3@early-bird.think.com> <1992Aug12.123449.5482@cs.cornell.edu>
- NNTP-Posting-Host: gandalf.think.com
- Keywords: macros, automatic defstructs
-
- In article <1992Aug12.123449.5482@cs.cornell.edu> raman@cs.cornell.edu (T. V. Raman) writes:
- >barmar@think.com (Barry Margolin) writes:
- >>I suspect your problem is that you aren't assigning the list to the
- >>variable at compile time (i.e. with (EVAL-WHEN (COMPILE) ...)), or you're
- >>side effecting a constant.
- >
- >I suspect that the reason is the above. I have never used eval-when
- >and in my code I simply have
- >
- >(defvar *list-of-dimensions* ...)
- >
- >and some calls at top level in the file that push items on to this
- >list using
- >(push item *list-of-dimensions*)
-
- The problem is that ordinary forms are executed only when the file is
- loaded. Thus, the PUSH won't happen until then. However, macros are
- expanded by the compiler. So if you have a macro that expands into a
- DEFSTRUCT, and it wants to use a global variable in computing the
- expansion, then you must make sure that this variable has been assigned
- before the macro is expanded.
-
- You can do this in two ways. One is to load the file that contains the
- DEFVAR and PUSHes before compiling anything that uses the macro.
-
- But if you want to use the macro in the same file as those forms appear,
- you have to use EVAL-WHEN to force them to execute during the compilation
- of the file.
-
- (eval-when (compile load eval)
- (defvar ...)
- (push ...)
- ...)
- --
- Barry Margolin
- System Manager, Thinking Machines Corp.
-
- barmar@think.com {uunet,harvard}!think!barmar
-