[racket] Macro : Reify a function body definition

From: Vincent Archambault-Bouffard (archambault.v at gmail.com)
Date: Tue Aug 19 11:41:49 EDT 2014


I am new to Racket. I have used another Scheme implementation before (Gambit) so I know a bit about Scheme in general.
I’m looking for a way to reify a function definition from a macro. The function is defined at phase 0 because it is used at runtime.

Simple example, suppose we want to differentiate a function :

(define (foo x) (+ x (sin x)))
(define fooPrime (derivative foo))

where “derivative" would be a macro that reify foo (looks-up the definition of and returns a syntax object) and generates its derivative.

I understand why macros cannot access phase 0 variable instances. (Composable and Compilable Macros: You Want it When?, Matthew Flatt, 2002) and that (syntax-local-value ) can do something similar with transformer binding. But the body definition is available at compile time.

I know the definition could be changed using a set! but for now I’m willing to ignore this corner case.

Thank you

Vincent Archambault-B

Posted on the users mailing list.