chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] Implementing a macroexpand-all


From: Patrick Li
Subject: Re: [Chicken-users] Implementing a macroexpand-all
Date: Fri, 11 Feb 2011 14:46:58 -0500

I've checked out expand* from the expand-full egg. And it contains the same problem as my macroexpand-full. 

It doesn't take into account local names that could shadow macro definitions.
eg.
(define-syntax when
  (syntax-rules ()
    ((when predicate body ...)
     (if predicate (begin body ...) '()))))

(macroexpand-all '(let ((when 2))
                    (when (< i 3)
                      (display i))))

The "when" should not be macroexpanded because it is a local binding introduced by the let form. In that context, it is actually *not* a macro.

Does anyone know which forms introduce new bindings? How can I check this up?
Thank you very much.
  -Patrick

On Fri, Feb 11, 2011 at 12:15 PM, Patrick Li <address@hidden> wrote:
No I didn't.
Thank you. I will check that out!


On Fri, Feb 11, 2011 at 11:42 AM, Christian Kellermann <address@hidden> wrote:
* Patrick Li <address@hidden> [110211 17:20]:
> Hello everyone,
>
> I'm trying to write a simple macroexpand-all function (a function to
> recursively macroexpand all subforms in a form until there are absolutely no
> macros left in the form), and realized that my naive implementation has a
> serious bug in it, namely that it doesn't keep track of local bindings
> within an expanded form.
>
> Naive implementation:
> (define (macroexpand-all _expression_)
>   (let ((expanded (expand _expression_)))
>     (if (pair? expanded)
>         (map macroexpand-all expanded)
>         expanded)))
>
> I want the function to obey this property:
> (eval some-_expression_) is *always* equivalent to (eval (macroexpand-all
> some-_expression_))
>
> Is there an easy or existing way to do this? I have tried to write my own,
> but do not know which special forms actually introduce new bindings.

Are you aware of expand* from the expand-full egg?

Kind regards,

Christian




reply via email to

[Prev in Thread] Current Thread [Next in Thread]