[racket] A Macro for Omitting Parentheses

From: Jay McCarthy (jay.mccarthy at gmail.com)
Date: Fri Nov 9 14:53:56 EST 2012

syntax-parse allows you to have multiple ...s, but there's ambiguity
about what to do about $ in before or after. You may want "(~and (~not
$) before) ... $ after ..."

Jay

On Fri, Nov 9, 2012 at 12:45 PM, Spencer Gordon <sgord512 at gmail.com> wrote:
> 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
>
> ____________________
>   Racket Users list:
>   http://lists.racket-lang.org/users
>



-- 
Jay McCarthy <jay at cs.byu.edu>
Assistant Professor / Brigham Young University
http://faculty.cs.byu.edu/~jay

"The glory of God is Intelligence" - D&C 93

Posted on the users mailing list.