[racket] handling curried functions in a 'define' macro

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Sat Feb 15 20:25:44 EST 2014

On Feb 15, 2014, at 8:05 PM, Matthew Butterick wrote:

> The macro noob (me) is experimenting with a macro that operates on define. I understand how to match the three common forms of define:
> 
> (define-syntax (define/foo stx)
>  (syntax-case stx ()
>    [(_ (name arg ... . rest-arg) body ...)
>     #'(omitted)]
>    [(_ (name arg ...) body ...)
>     #'(omitted)]
>    [(_ name body ...)
>     #'(omitted)]))
> 
> But how do I handle curried function definitions? Since they can be nested to arbitrary depth, I'm puzzled. Is there a way to match them directly in syntax-case? Or do I need a preliminary step of converting them into the basic define form, like so:
> 
> (define/foo (((bar a) b) c)
>  (+ a b c))
> 
> (define/foo bar
>  (λ(a) (λ(b) (λ(c) (+ a b c)))))
> 
> ... and then send them through the syntax-case I've already got.

I would definitely go the second route. It's an obvious match and remains readable for the maintainer. 



Posted on the users mailing list.