From: John Thingstad on
The Wed, 24 Mar 2010 16:27:52 +0200, Alex Mizrahi wrote:

> 6. If you're debugging macros, there are some tricks:
> * macroexpand it (duh!)
> * if you have problems only in certain context, or if you're debugging
> macrolet, macroexpand and print it _in that conext_.
> there is a magic macro for it:
>
> (defmacro mx1p (form &environment env)
> "Macroexpands form in context and prints it in macroexpansion time.
> Otherwise transparent"
> (print (macroexpand-1 form env))
> form)
>
> E.g. if you want to expansion of (foo 42) here:
>
> (macrolet ((foo (x) `(bar ,x)))
> (foo 42))
>
> Just wrap it with mx1p:
>
>
> (macrolet ((foo (x) `(bar ,x)))
> (mx1p (foo 42)))
>

SLIME has a command slime-macro-expand-1 (bound to C-c C-m) that does
this in the source..

(I find it helps to read the SLIME User manual from time to time as it
contains a lot of goodies..)

--------------
John Thingstad
From: szergling on
On Apr 26, 7:33 pm, John Thingstad <jpth...(a)online.no> wrote:
> The Wed, 24 Mar 2010 16:27:52 +0200, Alex Mizrahi wrote:
>
>
>
> > 6. If you're debugging macros, there are some tricks:
> > * macroexpand it (duh!)
> > * if you have problems only in certain context, or if you're debugging
> > macrolet, macroexpand and print it _in that conext_.
> > there is a magic macro for it:
>
> > (defmacro mx1p (form &environment env)
> > "Macroexpands form in context and prints it in macroexpansion time.
> > Otherwise transparent"
> > (print (macroexpand-1 form env))
> > form)
>
> > E.g. if you want to expansion of (foo 42) here:
>
> > (macrolet ((foo (x) `(bar ,x)))
> > (foo 42))
>
> > Just wrap it with mx1p:
>
> > (macrolet ((foo (x) `(bar ,x)))
> > (mx1p (foo 42)))
>
> SLIME has a command slime-macro-expand-1 (bound to C-c C-m) that does
> this in the source..

Perhaps you meant slime-macroexpand-1? All I got macroexpanding the
foo
form was (FOO 42), because it's been wrapped in a macrolet.

Maybe my slime is a bit old, but I'm not sure that's the same. mx1p
also "captures" the environment around the form to macroexpand,
so the macrolet example works. Slime's sexp-at-point (-for-
macroexpansion)
does not capture surrounding forms, and I'm not sure if that's
even practical?