[racket] A Macro for Omitting Parentheses

From: Spencer Gordon (sgord512 at gmail.com)
Date: Fri Nov 9 14:45:35 EST 2012

Hello,

I have been trying to write  a macro to allow me to omit some parentheses in complicated expressions with many complicated sub-expressions in the tail position. 

(I want the dollar sign to work exactly as it does in Haskell)

I want to be able to write 

> (map (lambda (str) (string-append "Hello, " str)) $ string-titlecase $ list "Alice "Bob" "Eve")

and have it expand to

> (map (lambda (str) (string-append "Hello, " str)) (string-titlecase (list "Alice "Bob" "Eve")))

My most recent attempt at this macro is 
 


> (define-syntax $
>   (lambda (stx)
>     (syntax-case stx ()
>       [(before ... $ after ...) 
>        #'(before bs ... (after as...))])))


but this does not work, as I cannot have multiple ellipses in the pattern I match against in syntax-case. 

I assume it is possible to write such a macro in Racket, but I am at a loss as to how.

Can anyone point me in the right direction, please? 

Thanks,
-Spencer Gordon



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20121109/6ab7750f/attachment.html>

Posted on the users mailing list.