8.12
Life, the Universe and Everything.
1 Introduction
<lue> ::=
(define lue 42)
Here is a macro:
(define-for-syntax mymacro-tmp (syntax-rules () [(_ a b) (let ((b 1)) a)])) (define-syntax (mymacro-stx stx) #`'#,(mymacro-tmp stx)) (define-syntax mymacro mymacro-tmp)
We can use it like this:
(mymacro (+ x 3) x)
Which expands to (requires Racket ≥ 6.4 and a bit of set-up boilerplate to have the output in scribble, see http://lists.racket-lang.org/users/archive/2014-December/065175.html):
'(let ((x 1)) (+ x 3))
The code above should show the expanded code, i.e:
<expanded-code> ::=
(let ((x 1)) (+ x 3))
<test-foo> ::=
(check-equal? lue 42)
2 Conclusion
<main-module> ::=
(module main typed/racket (require (for-syntax syntax/parse racket/syntax)) (provide lue) <lue> <scribble-macro-expansion>)
<module-test> ::=
(module* test typed/racket (require (submod "..") typed/rackunit) <test-foo>)
<*> ::=
(begin <main-module> (require 'main) (provide (all-from-out 'main)) <module-test>)