Add examples & slight fix for stxparam docs
This commit is contained in:
parent
470a8c8892
commit
5e78aa7d9e
|
@ -1,7 +1,13 @@
|
|||
#lang scribble/doc
|
||||
@(require "mz.rkt"
|
||||
scribble/eval
|
||||
(for-label racket/stxparam racket/stxparam-exptime racket/splicing))
|
||||
|
||||
@(define the-eval (make-base-eval))
|
||||
@(the-eval '(require racket/stxparam
|
||||
(only-in racket/control abort)
|
||||
(for-syntax racket/base)))
|
||||
|
||||
@title[#:tag "stxparam"]{Syntax Parameters}
|
||||
|
||||
@note-lib-only[racket/stxparam]
|
||||
|
@ -19,10 +25,20 @@ or @racket[syntax-parameter-value] (in a transformer). If
|
|||
@racket[expr] produces a procedure of one argument or a
|
||||
@racket[make-set!-transformer] result, then @racket[id] can be
|
||||
used as a macro. If @racket[expr] produces a
|
||||
@racket[rename-transformer] result, then @racket[id] can be
|
||||
@racket[make-rename-transformer] result, then @racket[id] can be
|
||||
used as a macro that expands to a use of the target identifier, but
|
||||
@racket[syntax-local-value] of @racket[id] does not produce
|
||||
the target's value.}
|
||||
the target's value.
|
||||
|
||||
@defexamples[#:eval the-eval
|
||||
(define-syntax-parameter current-class #f)
|
||||
(define-syntax-parameter yield (make-rename-transformer #'abort))
|
||||
(define-syntax-parameter define/public
|
||||
(λ (stx)
|
||||
(raise-syntax-error #f "use of a class keyword not in a class" stx)))
|
||||
(begin-for-syntax (displayln (syntax-parameter-value #'current-class)))
|
||||
(yield 5)
|
||||
]}
|
||||
|
||||
@defform[(syntax-parameterize ([id expr] ...) body-expr ...+)]{
|
||||
|
||||
|
@ -38,10 +54,31 @@ If an @racket[expr] produces a procedure of one argument or a
|
|||
@racket[make-set!-transformer] result, then its @racket[id]
|
||||
can be used as a macro during the expansion of the
|
||||
@racket[body-expr]s. If @racket[expr] produces a
|
||||
@racket[rename-transformer] result, then @racket[id] can be
|
||||
@racket[make-rename-transformer] result, then @racket[id] can be
|
||||
used as a macro that expands to a use of the target identifier, but
|
||||
@racket[syntax-local-value] of @racket[id] does not produce
|
||||
the target's value.}
|
||||
the target's value.
|
||||
|
||||
@defexamples[#:eval the-eval
|
||||
(define-syntax-parameter abort (syntax-rules ()))
|
||||
|
||||
(define-syntax forever
|
||||
(syntax-rules ()
|
||||
[(forever body ...)
|
||||
(call/cc (lambda (abort-k)
|
||||
(syntax-parameterize
|
||||
([abort (syntax-rules () [(_) (abort-k)])])
|
||||
(let loop () body ... (loop)))))]))
|
||||
|
||||
(define-syntax-parameter it (syntax-rules ()))
|
||||
|
||||
(define-syntax aif
|
||||
(syntax-rules ()
|
||||
[(aif test then else)
|
||||
(let ([t test])
|
||||
(syntax-parameterize ([it (syntax-id-rules () [_ t])])
|
||||
(if t then else)))]))
|
||||
]}
|
||||
|
||||
@; ----------------------------------------------------------------------
|
||||
|
||||
|
@ -88,3 +125,5 @@ This binding is provided @racket[for-syntax] by
|
|||
@racketmodname[racket/stxparam], since it is normally used in a
|
||||
transformer. It is provided normally by
|
||||
@racketmodname[racket/stxparam-exptime].}
|
||||
|
||||
@(close-eval the-eval)
|
||||
|
|
Loading…
Reference in New Issue
Block a user