From: Mark H Weaver <mhw@netris.org>
To: ludo@gnu.org (Ludovic Courtès)
Cc: guile-devel@gnu.org
Subject: Re: [PATCH] psyntax: custom ellipses using 'with-ellipsis' or R7RS syntax-rules
Date: Fri, 10 Jan 2014 12:08:47 -0500 [thread overview]
Message-ID: <877ga7wyqo.fsf@netris.org> (raw)
In-Reply-To: <87bnzkour2.fsf@gnu.org> ("Ludovic \=\?utf-8\?Q\?Court\=C3\=A8s\=22'\?\= \=\?utf-8\?Q\?s\?\= message of "Fri, 10 Jan 2014 14:02:09 +0100")
Hi Ludovic,
ludo@gnu.org (Ludovic Courtès) writes:
> Mark H Weaver <mhw@netris.org> skribis:
>
>> ludo@gnu.org (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
next prev parent reply other threads:[~2014-01-10 17:08 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-12-19 0:33 [PATCH] psyntax: custom ellipses using 'with-ellipsis' or R7RS syntax-rules Mark H Weaver
2014-01-08 11:41 ` Ludovic Courtès
2014-01-08 20:10 ` Mark H Weaver
2014-01-08 20:53 ` Ludovic Courtès
2014-01-09 23:07 ` Mark H Weaver
2014-01-10 13:02 ` Ludovic Courtès
2014-01-10 17:08 ` Mark H Weaver [this message]
2014-01-10 20:36 ` Ludovic Courtès
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=877ga7wyqo.fsf@netris.org \
--to=mhw@netris.org \
--cc=guile-devel@gnu.org \
--cc=ludo@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).