commit 0383c6bc49425ac457aefd38ba9de26930163217 parent f951d6609d30c1d36fd9ea0bee1748a00093b824 Author: JackFirth <jackhfirth@gmail.com> Date: Tue, 9 Dec 2014 20:31:24 -0800 Examples Add some example code Diffstat:
| A | examples.rkt | | | 21 | +++++++++++++++++++++ |
1 file changed, 21 insertions(+), 0 deletions(-)
diff --git a/examples.rkt b/examples.rkt @@ -0,0 +1,21 @@ +#lang racket + +(require (for-syntax syntax/parse)) + +(require generic-syntax-expanders) + +(define-syntax-with-expanders blah + (syntax-parser + [(_ (any ...)) + #'(begin (foo any) ...)])) + +(define-blah-expander baz + (syntax-parser + [(_ n:number) + #`(#,@(build-list (syntax-e #'n) values))])) + +(expand-once #'(blah (1 2 3 4 5))) +;; => expands to (begin (foo 1) (foo 2) (foo 3) (foo 4) (foo 5)) + +(expand-once #'(blah (baz 5))) +;; => expands to (begin (foo 0) (foo 1) (foo 2) (foo 3) (foo 4))