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

From: Asumu Takikawa (asumu at ccs.neu.edu)
Date: Sat Feb 15 20:49:32 EST 2014

On 2014-02-15 20:42:06 -0500, Asumu Takikawa wrote:
>   (define-syntax (my-define stx)
>     (syntax-case stx ()
>       [(_ . rst)
>        (define-values (id rhs)
>          (normalize-definition stx #'my-lambda))
>        #'(define #,id #,rhs)]))

I should actually try the examples I write. Here's a version that should
work:

  (require (for-syntax syntax/define))

  ;; silly lambda that just runs body twice
  (define-syntax-rule (my-lambda (x ...) b)
    (lambda (x ...) b b))

  (define-syntax (my-define stx)
    (syntax-case stx ()
      [(_ . rst)
       (begin
        (define-values (id rhs)
          (normalize-definition stx #'my-lambda))
        #`(define #,id #,rhs))]))

  (my-define (f x) (displayln x))
  (f 3)

Cheers,
Asumu

Posted on the users mailing list.