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

Re: nested macros and intentional hygiene violation



Bruce Hoult wrote:
> 
> Is the ?= hygiene violation indicator intended to allow a nested macro
> to refer to bindings introduced by a surrounding macro, or only to
> bindings in the top-level source code?

I am inclined to say the former, but if I think of macro-introduced identifiers
being hygienic (kind-of gensymed) it may be that they cannot be captured even with an unhygienic reference.

So just introduce a macro biding using ?= and capture it using ?=.

But as the implementor of unhygienic name references for macros, I would wery much like to hear a word on this from a real authority.

	Gabor


> 
> e.g.
> 
> define macro do-combinations
>   {do-combinations (?names:* in ?list:expression) ?:body end} =>
>     {let list = ?list;
>      let (init, limit, next-state, finished?,
>           current-key, current-element,
>           current-element-setter, copy-state)

Try:

>           current-element-setter, ?=copy-state)

etc.

>        = forward-iteration-protocol(list);
>      do-combinations-body
>        (?names in list from init
>           using limit next-state finished? current-element
>           in ?body)}
> end macro;
> 
> define macro do-combinations-body
>   {do-combinations-body
>      (?:name in ?list:name from ?init:expression
>         using ?limit:name ?next-state:name ?finished?:name
>               ?current-element:name
>         in ?:body)}
>     => {for (state = ?init then ?next-state(?list, state),
>              until: ?finished?(?list, state, ?limit))
>           let ?name = ?current-element(?list, state);
>           ?body;
>        end};
> 
>   {do-combinations-body
>      (?:name, ?names:* in ?list:name from ?init:expression
>         using ?limit:name ?next-state:name ?finished?:name
>         ?current-element:name
>         in ?:body)}
>     => {for (state = ?init then ?next-state(?list, state),
>              until: ?finished?(?list, state, ?limit))
>           let ?name = ?current-element(?list, state);
>           do-combinations-body
>             (?names in ?list
>                from ?next-state(?list, ?=copy-state(?list, state))
>                using ?limit ?next-state ?finished? ?current-element
>                in ?body)
>         end};
> end macro;
> 
> This produces an error (Undefined variable: copy-state) in Gwydion Dylan
> when the second case in do-combinations-body attempts to use ?= to refer
> to the binding of copy-state introduced in do-combinations.
> 
> The macro works fine when I explicitly pass copy-state from one macro
> invocation to another, as I'm doing for limit, next-state, finished?,
> and current-element.
> 
> It also works fine if I hand-expand the body of do-combinations:
> 
> begin
>   let list = #("the", "quick", "brown", "fox", "jumps");
>   let (init, limit, next-state, finished?, current-key, current-element,
>        current-element-setter, copy-state)
>     = forward-iteration-protocol(list);
>   do-combinations-body
>     (x,y,z in list from init
>        using limit next-state finished? current-element
>        in format-out("%= %= %=\n", x, y, z))
> end;
> 
> Clearly I'd like to be able to *not* have to explicitly pass all those
> things through.
> 
> -- Bruce



#feed the animals
#feed the animals
#feed the animals
#feed the animals
#feed the animals
#feed the animals
#feed the animals
#feed the animals
#feed the animals
#feed the animals
#feed the animals
#feed the animals
#feed the animals
#feed the animals
#feed the animals
#feed the animals
#feed the animals
#feed the animals
#feed the animals
#feed the animals
#feed the animals
#feed the animals
#feed the animals
#feed the animals
#feed the animals
#feed the animals
#feed the animals
#feed the animals
#feed the animals
#feed the animals
#feed the animals
#feed the animals
#feed the animals
#feed the animals
#feed the animals
#feed the animals
#feed the animals
#feed the animals
#feed the animals
#feed the animals
#feed the animals
#feed the animals
#feed the animals
#feed the animals
#feed the animals
#feed the animals
#feed the animals
#feed the animals
#feed the animals
#feed the animals
#feed the animals