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

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Sat Feb 15 21:33:09 EST 2014

It's the beginner's version of what Asumu proposed. Perfectly acceptable. 


On Feb 15, 2014, at 9:27 PM, Matthew Butterick wrote:

> Thanks for the suggestions. In the meantime I came up with this noobtastic recursive approach, which seems to work so far. It simplifies every definition form to the basic (define name body ...) form, and then performs the syntax transformation on that. (Bad idea?)
> 
> This is sufficient for my macro because I'm just rewriting define, and don't need to inspect the arguments more closely.
> 
> (define-syntax (define/foo stx)
>  (syntax-case stx ()
>    [(_ (proc arg ... . rest-arg) body ...)
>     #'(define/foo proc
>         (λ(arg ... . rest-arg) body ...))]
>    [(_ name body ...)
>     #'(do-transform)]))
> 
> 
> On Feb 15, 2014, at 5:49 PM, Asumu Takikawa <asumu at ccs.neu.edu> wrote:
> 
>> 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
> 
> 
> ____________________
>  Racket Users list:
>  http://lists.racket-lang.org/users



Posted on the users mailing list.