guile-devel
[Top][All Lists]
Advanced

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

Re: [PATCH] psyntax: custom ellipses using 'with-ellipsis' or R7RS synta


From: Mark H Weaver
Subject: Re: [PATCH] psyntax: custom ellipses using 'with-ellipsis' or R7RS syntax-rules
Date: Fri, 10 Jan 2014 12:08:47 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)

Hi Ludovic,

address@hidden (Ludovic Courtès) writes:

> Mark H Weaver <address@hidden> skribis:
>
>> address@hidden (Ludovic Courtès) writes:
>
> [...]
>
>>> Actually my question was more about the ellipsis escaping form
>>> (... ...).  It is affected by ‘with-ellipsis’, right?
>>
>> Yes, so the following works:
>>
>>   (define-syntax define-inline
>>     (with-ellipsis ---
>>       (syntax-rules ()
>>         ((_ (name parms ---) exp ---)
>>          (define-syntax name
>>            (with-ellipsis (--- ---)
>>              (syntax-rules ()
>>                ((_ args (--- ---))
>>                 ((lambda (parms ---) exp ---)
>>                  args (--- ---))))))))))
>
>
> Sorry I wasn’t clear.  Does this work:
>
>   (define-syntax define-inline
>     (with-ellipsis ---
>       (syntax-rules ()
>         ((_ (name parms ---) exp ---)
>          (define-syntax name
>            (with-ellipsis ---                  ; <- note here!
>              (syntax-rules ()
>                ((_ args (--- ---))
>                 ((lambda (parms ---) exp ---)
>                  args (--- ---))))))))))
>
> IOW, does the escaping syntax adjust to the current ellipsis?

Yes, the escaping syntax does adjust to the current ellipsis, but no,
your example won't work.  It differs from the working code I gave in
just one respect: you passed "---" as the first operand to
'with-ellipsis', whereas I passed "(--- ---)".

Since you chose the same ellipsis identifier for both the inner and
outer macros, you need to escape the ellipsis passed to the inner
'with-ellipsis', just as you need to escape any ellipsis that you want
to remain present in the generated code.

Remember that macros are expanded from the outside in.  When
(define-inline (foo a b c) (list a b c)) is expanded, at that point the
entire inner 'define-syntax' form is just a template, and it has no
understanding of the inner syntax forms.  Therefore, it will interpret
your inner "with-ellipsis ---" as meaning that 'with-ellipsis' should be
a pattern variable.  You need to write "with-ellipsis (--- ---)"
instead, which will expand into "with-ellipsis ---" in the generated
code.

>> Needless to say, the whole point of custom ellipses is to avoid having
>> to ever escape ellipses, but you can still do it.
>
> Yes of course; that’s an academic question to satisfy my curiosity.

[...]

>> I ended up making the effect of 'with-ellipsis' propagate into syntax
>> definition forms, since the semantics seem simpler to me.
>
> OK.
>
> So does that mean that in the example above the second ‘with-ellipsis’
> can now be omitted, or is it limited to ‘let...-syntax’?

No, it's not limited to 'let...-syntax'.  The effect of 'with-ellipsis'
propagates into 'define-syntax' forms well.

However, you still need the second 'with-ellipsis' in your example,
because the effect of 'with-ellipsis' does not affect the ellipsis of
the generated code.  If you want one macro to generate another macro
definition that uses a custom ellipsis, you must include 'with-ellipsis'
in the generated code.

    Regards,
      Mark



reply via email to

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