[racket] paren-shape

From: Jens Axel Søgaard (jensaxel at soegaard.net)
Date: Sun May 13 14:25:56 EDT 2012

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}

Posted on the users mailing list.