From f48b567901a42942ee48a4c6e8f7d640f0907088 Mon Sep 17 00:00:00 2001 From: Jon Rafkind Date: Wed, 16 Sep 2009 19:03:55 +0000 Subject: [PATCH] add better example for define-for-syntax svn: r16025 --- collects/scribblings/reference/syntax.scrbl | 29 +++++++++++++-------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/collects/scribblings/reference/syntax.scrbl b/collects/scribblings/reference/syntax.scrbl index 5a6ff2d477..7e171cc41d 100644 --- a/collects/scribblings/reference/syntax.scrbl +++ b/collects/scribblings/reference/syntax.scrbl @@ -1928,17 +1928,24 @@ Evaluation of @scheme[expr] side is @scheme[parameterize]d to set @scheme[current-namespace] as in @scheme[let-syntax].} @defexamples[#:eval (syntax-eval) -(define-for-syntax foo 2) -(define-syntax bar - (lambda (syntax-object) - (printf "foo is ~a\n" foo) - #'2)) -(bar) -(define-syntax (bar2 syntax-object) - (printf "foo is ~a\n" foo) - #'3) -(bar2) -] +(define-for-syntax helper 2) +(define-syntax (make-two syntax-object) + (printf "helper is ~a\n" helper) + #'2) +(make-two) +(code:comment @#,t{`helper' is not bound in the runtime phase}) +helper + +(define-for-syntax (filter-ids ids) + (filter identifier? ids)) +(define-syntax (show-variables syntax-object) + (syntax-case syntax-object () + [(_ expr ...) + (with-syntax ([(only-ids ...) + (filter-ids (syntax->list #'(expr ...)))]) + #'(list only-ids ...))])) +(let ([a 1] [b 2] [c 3]) + (show-variables a 5 2 b c))] @defform[(define-values-for-syntax (id ...) expr)]{