[plt-scheme] Extending macro pattern syntax

From: James Coglan (jcoglan at googlemail.com)
Date: Sat Jan 31 15:22:59 EST 2009

>
>  For example, there's no reason the pattern (_ (name value) ... expr) could
>> not be made to work, since 'expr' is a less specific matcher than '(name
>> value)'. '(name value) ...' would consume input expressions until it hit a
>> non-list expression, then 'expr' would take over. So firstly, are there
>> counterexamples to prove this wouldn't work, and if it would work, can you
>> implement it using Scheme macros themselves? I'd also like to do something
>> similar with keywords, so that for example (_ expr ... stop stmt ...) would
>> work if 'stop' is a keyword for the syntax.
>>
>
> And in fact it already works in PLT Scheme:
>
> #lang scheme
>
> (define-syntax foo
>  (syntax-rules ()
>    [(foo a b ... c)
>     '(a b ... c)]))
>
> (foo 1 2 3) ; =: (1 2 3)
>
>
> (define-syntax bar
>  (syntax-rules ()
>    [(foo a b ... ignore)
>     '(a b ...)]))
>
> (bar 1 2 3) ; => (1 2)



Okay, I tried that out in mzscheme and it was fine. I ask because I'm
implementing R5RS myself, and I was wondering whether it's possible to
implement some of the R6RS additions (like infix ellipses) as R5RS macros.
If you have examples that would be great.

I'd also like keywords to be used to stop ellipses consuming input, i.e. the
following would be fine:

(define-syntax foo
 (syntax-rules (word)
   [(foo a b ... word c ...)
    '(a b ... c)]))

This would allow very flexible custom syntaxes but mzscheme choked when I
tried it. Is it possible to implement this using macros or does the host
implementation need to provide explicit support for it?

(Sorry if any of this seems obtuse and impractical, I'm just poking around
to improve my understanding.)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20090131/6b1dd7d1/attachment.html>

Posted on the users mailing list.