EVAL occasionally expands macros twice

Bug #541584 reported by Richard Holcombe on 2010-03-18
This bug affects 1 person
Affects Status Importance Assigned to Milestone

Bug Description

I execute the following code:

(defvar *arglist* nil)
(defmacro test2(x)
(push x *arglist*)
`(setf ,x 7)))

(test2 y)

then *arglist* has the value (y y) when just (y) is expected. (at least (y) is what I get on all of the other lisps that I can find, and makes much more sense.)

This occurs at least on versions 1.0.33 and 1.0.36 on linux.

uname -a
Linux 2.6.31-20-generic #58-Ubuntu SMP Fri Mar 12 05:23:09 UTC 2010 i686 GNU/Linux



Changed in sbcl:
status: New → In Progress
Nikodemus Siivola (nikodemus) wrote :

Strictly speaking IIRC, macros are allowed to be expanded multiple times, what is going on here seems unintentional.

summary: - incorrect macro evaluation
+ EVAL occasionally expands macros twice
Changed in sbcl:
status: In Progress → Confirmed
Changed in sbcl:
importance: Undecided → Low
status: Confirmed → Triaged
Douglas Katzman (dougk) wrote :

This behavior is a consequence of *evaluator-mode* being :compile.
The REPL tries to use an extremely rudimentary evaluation strategy to avoid calling the compiler.
The first thing that it has to do to try interpreting a form is to macroexpand it, accounting for one call of TEST2.

For a variety of reasons the simplistic evaluator will give up, and call the compiler, which it does using the original form.
In this case it's a SETQ of an unknown variable that is not handled by the simple evaluator, so it then calls the compiler on the original form, which has to be expanded again.
If Y had been DEFVAR'ed, the simple evaluator would have done the SETQ and not called the compiler.

As Nikodemus remarked, this is permissible behavior. With *evaluator-mode* = :interpret, only one macroexpansion occurs.
Basically not a bug.

Changed in sbcl:
status: Triaged → Won't Fix
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers