From: Jeff Dalton

Subject: Re: Bug in macrolet?

Date: 1999-7-6 11:18

Steve Haflich <franz.com at smh> wrote:

> To: <cs.berkeley.edu at allegro-cl> > Subject: Bug in macrolet? > From: Antonio Leitao <gia.ist.utl.pt at aml> > > I found a little problem in Allegro CL 5.0 (Linux) with interpreted > code. > > In the following definition, > > (defun foo (x) > (macrolet ((bar () > x)) > (+ x (bar)))) > > the macrolet form is accessing a variable x which is not accessible at > the time of the macro expansion. > > If I compile the file containing the above definition, I get an error > during macroexpansion, as expected. What is not expected is that when > I run the same example interpreted, I can call foo. > > (foo 1) -> 2 > > I believe Allegro behavior conforms to the ANS in this case, both > compiled and interpreted behavior. > > It's pretty clear what you _expect_ to happen, but I wonder why you > expect that behavior. In particular, can you justify your > expectations from the ANS and cite the relevant passages? > [...] > I'm absolutely sure CLUCL behavior is also correct in this regard.
I would certainly *expect* an error when both running interpreted and when the code is compiled. Moreover, I *do* get an error in both cases in CMUCL, and in GCL, for that matter. The "and GCL" part is interesting, because, where people expect CMUCL to do an unusual amount of analysis, so that it might do some compiler-like things when interpreting, no one would expect that from GCL. (They'd be slightly wrong in this case, but not in a way that matters.) Hence I find Steve's reply a bit opaque, since he seems to be saying both CMUCL and Allegro are conforming, without giving any hint as to his reasoning, instead challenging the other guy to come up with passages from the ANS. So ... here is a relevant passage (from the "Special Operator FLET, LABELS, MACROLET" entry in the Hyperspec): The macro-expansion functions defined by macrolet are defined in the lexical environment in which the macrolet form appears. Declarations and macrolet and symbol-macrolet definitions affect the local macro definitions in a macrolet, but the consequences are undefined if the local macro definitions reference any local variable or function bindings that are visible in that lexical environment. There it is: *the consequences are undefined* if the local macro definitions reference any local variable or function bindings that are visible in that lexical environment. The remaining question is how does Allegro manage to get the behaviour it does, since it is (I'd say) rather unexpected? And why? -- jeff