[armedbear-devel] MACROLET environment issue in DO?

Theam Yong Chew senatorzergling at gmail.com
Sat Aug 11 09:32:21 UTC 2012


Hi devs,

I've just stumbled upon something that looks buggy. In the following
form, I am particularly focusing on the end-test-form in the do macro.


(macrolet ((foo ()
             '(print "macrolet foo")))
  (foo)
  (do ((p 0 (1+ p)))
      ((foo))
    (print "LOOP")))
Prints
"macrolet foo"
"macrolet foo"
then returns
==> NIL

Looks fine, but if I wrap that in a function,

(defun use-foo ()
  (macrolet ((foo ()
               '(print "macrolet foo")))
    (foo)
    (do ((p 0 (1+ p)))
        ((foo))
      (print "LOOP"))))

(use-foo)
Prints "macrolet test"
then raises an error:

The function FOO is undefined.
   [Condition of type UNDEFINED-FUNCTION]

Restarts:
 0: [CONTINUE] Try again.
 1: [USE-VALUE] Specify a function to call instead.
 2: [RETURN-VALUE] Return one or more values from the call to FOO.
 3: [RETRY] Retry SLIME interactive evaluation request.
 4: [*ABORT] Return to SLIME's top level.
 5: [ABORT] Abort thread.

Backtrace:
  0: (#<FUNCTION {1879842}> #<UNDEFINED-FUNCTION {1426780}> #<FUNCTION
{1879842}>)
  1: (APPLY #<FUNCTION {1879842}> (#<UNDEFINED-FUNCTION {1426780}>
#<FUNCTION {1879842}>))
  2: (SYSTEM::RUN-HOOK SYSTEM::*INVOKE-DEBUGGER-HOOK*
#<UNDEFINED-FUNCTION {1426780}> #<FUNCTION {1879842}>)
  3: (INVOKE-DEBUGGER #<UNDEFINED-FUNCTION {1426780}>)
  4: (ERROR #<UNDEFINED-FUNCTION {1426780}>)
  5: (SYSTEM:UNDEFINED-FUNCTION-CALLED FOO NIL)
  6: (FOO)
      Locals:
        "??" = "??"
  7: (USE-FOO)
      Locals:
        "??" = "??"
  8: (SYSTEM::%EVAL (USE-FOO))
      Locals:
        "??" = "??"
  9: (EVAL (USE-FOO))
      Locals:
        "??" = "??"
....





If I define a function with same name as the local macro,

(defun test ()
  (print "function test"))

(defun use-test ()
  (macrolet ((test ()
               '(print "macrolet test")))
    (test)
    (do ((p 0 (1+ p)))
        ((test))
      (print "LOOP"))))

(use-test)
Prints
"macrolet test"
"function test"
then returns
==> NIL


If I manually macroexpand the do form & substitute the expansion
back into the function (with some gensym tidy up),

(defun macro-expanded-do ()
  (macrolet ((test ()
               '(print "macrolet test")))
    (test)
    (BLOCK NIL
      (LET ((P 0))
        (TAGBODY (GO G4759)
           G4758 (PRINT "LOOP")
           (PSETQ P (1+ P))
           G4759 (UNLESS (TEST) (GO G4758))
           (RETURN-FROM NIL (PROGN)))))))

(macro-expanded-do)
Prints
"macrolet test"

"macrolet test" ; No value
and returns
==> NIL

Is this a bug? I'm running on Windows, using

(lisp-implementation-version)
==> "1.0.1-svn-13750-13751"


Thanks,

Yong.




More information about the armedbear-devel mailing list