[racket-users] Re: Custom define macro

2017-01-20 Thread Lehi Toskin
That's perfect, Thank you!

On Friday, January 20, 2017 at 2:46:49 PM UTC-8, Matthew Butterick wrote:
> Perhaps a job for `normalize-definition`? It handles all the syntactic 
> disentangling in a `define`-like macro.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[racket-users] Re: Custom define macro

2017-01-20 Thread Matthew Butterick
On Friday, January 20, 2017 at 1:49:12 PM UTC-8, Lehi Toskin wrote:
> I have created a macro[1] that operates like regular define, but wraps the 
> definition around a struct with prop:procedure. This struct contains the 
> procedure to be used and a list representation of its definition. I've gotten 
> it to where I'm happy with its coverage (single arity, rest-args, etc.), but 
> one thing eludes me: currying. What I would like to do is take care of forms 
> like (define ((add n) m) (+ n m)) and have it transformed to be (lambda (n) 
> (lambda (m) (+ n m)). I've been able to pick apart the list '((add n) m) and 
> transform it myself, but putting it inside the macro makes things 
> complicated. 

Perhaps a job for `normalize-definition`? It handles all the syntactic 
disentangling in a `define`-like macro.


;;;
#lang racket
(require (for-syntax syntax/define))

(define-syntax (def stx)
  (with-syntax ([(id lambda-exp) (let-values ([(id-stx body-exp-stx) 
(normalize-definition stx #'lambda #t #t)])
   (list id-stx body-exp-stx))])
#'(define id lambda-exp)))

(def foo 42)
foo ; 42

(def (bar x) x)
(bar 12) ; 12

(def ((zam x) y) (list x y))
((zam 'this) 'that) ; '(this that)

(def zoom (λ (x) (* x x)))
(zoom 7) ; 49

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.