[racket] matching optional keyword + value

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

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)?

Thanks,
Laurent
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20120427/d00da823/attachment.html>

Posted on the users mailing list.