[racket] Pattern matching define macro
I just found this, which has a lot of forms for just about everything I can think of (and more) that support things like match-patterns:
https://github.com/stchang/generic-bind
I haven’t tried it yet, but It looks pretty amazing.
It probably has everything you want.
On Jul 13, 2014, at 12:41 AM, Alexander D. Knauth <alexander at knauth.org> wrote:
>
> On Jul 12, 2014, at 10:17 PM, Alexander D. Knauth <alexander at knauth.org> wrote:
>
>>
>> On Jul 12, 2014, at 6:43 PM, Brian Adkins <racketusers at lojic.com> wrote:
>>
>>> I probably won't keep my defpat macro, at least not in its present form (for one, it only handles a single arg); there's probably a balance between being concise and being general/flexible.
>>
>> Although define/match is definitely more powerful, if you want it, this would probably be a good version of what you want that would handle multiple arguments: (I’ll reply again if I get one to work with optional and/or keyword-arguments)
>> (define-syntax defpat
>> (syntax-rules ()
>> [(defpat (f arg-pat ...) body ...)
>> (defpat f (match-lambda** [(arg-pat ...) body ...]))]
>> [(defpat id expr)
>> (define id expr)]))
>
> Ok I just made a version of defpat that can handle multiple arguments, optional arguments, keyword-arguments, and optional keyword-arguments.
> I also made a form called my-match-lambda that defpat uses to do this.
> https://github.com/AlexKnauth/defpat
> Also to do this I had to make it so that you have to use square brackets to specify optional arguments, otherwise it couldn’t tell between an optional argument and a match pattern.
>