[racket] Using syntax/parse, how to accept keyword arguments in any order yet not allow duplicates?

From: Eric Dobson (eric.n.dobson at gmail.com)
Date: Sun Apr 7 20:35:20 EDT 2013

You want ~once. See
http://docs.racket-lang.org/syntax/stxparse-patterns.html?q=syntax-parse#%28form._%28%28lib._syntax%2Fparse..rkt%29._~7eonce%29%29
and http://docs.racket-lang.org/syntax/More_Keyword_Arguments.html?q=syntax-parse.

On Sun, Apr 7, 2013 at 5:23 PM, Scott Klarenbach <scott at pointyhat.ca> wrote:
> Hi there,
>
> I'd like to create a macro that accepts non-optional keyword arguments in
> any order.  It should however, ensure that all the arguments are provided.
> Finally, it should not allow duplicates.
>
> So far I've only been able to solve for my first criteria.
>
> As a test, I have this:
>
> (syntax-parse stx
>   [(a:id b:id (~or (~seq #:key1 c:id) (~seq #:key2 d:id)) ...) #t])
>
> Now, that matches for:
> #'(a b #:key1 hey #:key2 there)
> #'(a b #:key2 there #:key1 hey)
>
> Which is what I want.  But unfortunately it also matches:
> #'(a b #:key2 there)
>
> And worse:
> #'(a b #:key2 one #:key2 two #:key2 three)
>
> The reasons are obvious.  I'm just wondering if there's a more robust way of
> dealing with these types of scenarios that I'm missing?  I thought of
> combining an (~or (~and clause but that becomes very tedious, and leaves the
> duplicate problem unsolved.
>
> Thanks.
>
> --
> Talk to you soon,
>
> Scott Klarenbach
>
> PointyHat Software Corp.
> www.pointyhat.ca
> p 604-568-4280
> e scott at pointyhat.ca
> 200-1575 W. Georgia
> Vancouver, BC V6G2V3
>
> _______________________________________
> To iterate is human; to recur, divine
>
> ____________________
>   Racket Users list:
>   http://lists.racket-lang.org/users
>

Posted on the users mailing list.