[racket] matching optional keyword + value

From: Laurent (laurent.orseau at gmail.com)
Date: Fri Apr 27 08:32:58 EDT 2012

On Fri, Apr 27, 2012 at 14:18, Sam Tobin-Hochstadt <samth at ccs.neu.edu>wrote:

> On Fri, Apr 27, 2012 at 8:03 AM, Laurent <laurent.orseau at gmail.com> wrote:
> > Hi,
> >
> > I'm trying to match form declarations that can contain optional
> > keyword-followed-by-something (more precisely matching "defforms"
> > declarations).
> > It looks like (id [#:kw1 val1] x [#:kw2 val2] ....) where the [] means
> > optional.
> > For example the list to match may be '(a b) or '(a #:kw1 1 b) or  '(a b
> > #:kw2 2) or '(a #:kw1 3 b #:kw2 4), etc.
> >
> > But I couldn't figure out how to say "match 2 things one after the
> other, 0
> > or 1 time".
> > Something like that could do it:
> > (match L
> >   [`(,id ,@(list '#:kw1 v1) ... ,x ,@(list '#:kw2 v2) ...  ....)
> >   ....])
> >
> > but nothing I tried got close to it (the ... are quoted and don't like
> being
> > unquoted).
> > Google gave me that result:
> >
> http://stackoverflow.com/questions/7061533/match-form-in-racket-scheme-question-about-matching-sequences
> > but that's not really what I'm after.
> >
> > Is there any way to do that with match patterns without doing some
> > recurrence over `match' myself (and not writing all the possible
> composition
> > of with/without each keyword)?
>
> `match' doesn't support the repetition constraints and other
> extensions to ... patterns that `syntax-parse' does.  `list-no-order'
> patterns might be helpful here, though.
>

ok, never mind, tanks.


> If you're processing the contents of a `defform' call, probably the
> right thing to do is just just use `syntax-parse' -- it's great for
> this sort of thing.
>

Actually, the defforms are read directly from a scribble file, so it's not
a call.
Is it possible to have syntax-parse deal directly with values instead of
syntax objects?
(I suppose I could turn the read list into a syntax object, but that's
probably not the best way to do it, is it?)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20120427/d6aea487/attachment.html>

Posted on the users mailing list.