[racket] paren-shape

From: Danny Yoo (dyoo at hashcollision.org)
Date: Sun May 13 15:45:16 EDT 2012

Does this apply?
http://lists.racket-lang.org/dev/archive/2012-March/009205.html

On Sunday, May 13, 2012, Jens Axel Søgaard wrote:

> Hi All,
>
> I am playing around with the paren-shape syntax property
> in order to use {} for polynomials.
>
> The case {+ p q r ...} is causing me problems.
>
> I have reduced the problem to the example below.
>
> I'd like {+ 2 3 5} to expand to (* (* 2 3) 5) and thus evaluate to 30.
> However as is {+ 2 3 5} expands to (#%app + (#%app * '2 '3) '5)
> which gives 11.
>
> What have I missed?
>
> /Jens Axel
>
>
> #lang racket
>
> (module huh racket
>  (provide (rename-out [app #%app]))
>
>  (define-for-syntax (curlify stx)
>    (syntax-property stx 'paren-shape #\{))
>
>  (define-for-syntax (curly? stx)
>    (let ([p (syntax-property stx 'paren-shape)])
>      (and p (eqv? p #\{))))
>
>  (define-syntax (app stx)
>    (syntax-case stx (+)
>      [{_ + p q}
>       (curly? stx)
>       (syntax/loc stx (* p q))]
>      [{_ + p q r ...}
>       (curly? stx)
>       (curlify #'{app + (* p q) r ...})]
>      [(_ . more)
>       (syntax/loc stx (#%app . more))])))
>
> (require 'huh)
> {+ 2 3 5}
> ____________________
>  Racket Users list:
>  http://lists.racket-lang.org/users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20120513/13151968/attachment.html>

Posted on the users mailing list.