fix typos
This commit is contained in:
parent
8da2f537fb
commit
b57cf0134f
|
@ -16,9 +16,11 @@ expands to a use of @racket[unchecked-go]:
|
||||||
#:file "m.rkt"
|
#:file "m.rkt"
|
||||||
racket
|
racket
|
||||||
(provide go)
|
(provide go)
|
||||||
|
|
||||||
(define (unchecked-go n x)
|
(define (unchecked-go n x)
|
||||||
(code:comment @#,t{to avoid disaster, @racket[n] must be a number})
|
(code:comment @#,t{to avoid disaster, @racket[n] must be a number})
|
||||||
(+ n 17))
|
(+ n 17))
|
||||||
|
|
||||||
(define-syntax (go stx)
|
(define-syntax (go stx)
|
||||||
(syntax-case stx ()
|
(syntax-case stx ()
|
||||||
[(_ x)
|
[(_ x)
|
||||||
|
@ -79,8 +81,11 @@ output. Building on the previous example,
|
||||||
#:file "n.rkt"
|
#:file "n.rkt"
|
||||||
racket
|
racket
|
||||||
(require "m.rkt")
|
(require "m.rkt")
|
||||||
|
|
||||||
(provide go-more)
|
(provide go-more)
|
||||||
|
|
||||||
(define y 'hello)
|
(define y 'hello)
|
||||||
|
|
||||||
(define-syntax (go-more stx)
|
(define-syntax (go-more stx)
|
||||||
(syntax-protect #'(go y)))
|
(syntax-protect #'(go y)))
|
||||||
]
|
]
|
||||||
|
@ -99,14 +104,18 @@ input to its output.
|
||||||
@section{Tainting Modes}
|
@section{Tainting Modes}
|
||||||
|
|
||||||
In some cases, a macro implementor intends to allow limited
|
In some cases, a macro implementor intends to allow limited
|
||||||
destructuring of a macro result without losing the result's
|
destructuring of a macro result without tainting the result.
|
||||||
certificate. For example, given the following @racket[define-like-y]
|
For example, given the following @racket[define-like-y]
|
||||||
macro,
|
macro,
|
||||||
|
|
||||||
@racketmod[
|
@racketmod[
|
||||||
|
#:file "q.rkt"
|
||||||
racket
|
racket
|
||||||
|
|
||||||
(provide define-like-y)
|
(provide define-like-y)
|
||||||
|
|
||||||
(define y 'hello)
|
(define y 'hello)
|
||||||
|
|
||||||
(define-syntax (define-like-y stx)
|
(define-syntax (define-like-y stx)
|
||||||
(syntax-case stx ()
|
(syntax-case stx ()
|
||||||
[(_ id) (syntax-protect #'(define-values (id) y))]))
|
[(_ id) (syntax-protect #'(define-values (id) y))]))
|
||||||
|
@ -120,7 +129,7 @@ someone may use the macro in an internal definition:
|
||||||
x)
|
x)
|
||||||
]
|
]
|
||||||
|
|
||||||
The implementor of the @racket[q] module most likely intended to allow
|
The implementor of the @filepath{q.rkt} module most likely intended to allow
|
||||||
such uses of @racket[define-like-y]. To convert an internal definition
|
such uses of @racket[define-like-y]. To convert an internal definition
|
||||||
into a @racket[letrec] binding, however, the @racket[define] form
|
into a @racket[letrec] binding, however, the @racket[define] form
|
||||||
produced by @racket[define-like-y] must be deconstructed, which would
|
produced by @racket[define-like-y] must be deconstructed, which would
|
||||||
|
@ -203,8 +212,10 @@ a macro:
|
||||||
@racketmod[
|
@racketmod[
|
||||||
racket
|
racket
|
||||||
(provide def-go)
|
(provide def-go)
|
||||||
|
|
||||||
(define (unchecked-go n x)
|
(define (unchecked-go n x)
|
||||||
(+ n 17))
|
(+ n 17))
|
||||||
|
|
||||||
(define-syntax (def-go stx)
|
(define-syntax (def-go stx)
|
||||||
(syntax-case stx ()
|
(syntax-case stx ()
|
||||||
[(_ go)
|
[(_ go)
|
||||||
|
@ -217,21 +228,24 @@ racket
|
||||||
|
|
||||||
When @racket[def-go] is used inside another module to defined
|
When @racket[def-go] is used inside another module to defined
|
||||||
@racket[go], and when the @racket[go]-defining module is at a
|
@racket[go], and when the @racket[go]-defining module is at a
|
||||||
different protection level than the @racket[def-go] module, the
|
different protection level than the @racket[def-go]-defining module, the
|
||||||
generated macro's use of @racket[protect-syntax] is not right. The
|
generated macro's use of @racket[protect-syntax] is not right. The
|
||||||
use of @racket[unchecked-go] should be protected at the level of the
|
use of @racket[unchecked-go] should be protected at the level of the
|
||||||
@racket[def-go] module, not the @racket[go] module.
|
@racket[def-go]-defining module, not the @racket[go]-defining module.
|
||||||
|
|
||||||
The solution is to define and use @racket[protect-go-syntax], instead:
|
The solution is to define and use @racket[go-syntax-protect], instead:
|
||||||
|
|
||||||
@racketmod[
|
@racketmod[
|
||||||
racket
|
racket
|
||||||
(provide def-go)
|
(provide def-go)
|
||||||
|
|
||||||
(define (unchecked-go n x)
|
(define (unchecked-go n x)
|
||||||
(+ n 17))
|
(+ n 17))
|
||||||
|
|
||||||
(define-for-syntax go-syntax-protect
|
(define-for-syntax go-syntax-protect
|
||||||
(let ([insp (current-code-inspector)])
|
(let ([insp (current-code-inspector)])
|
||||||
(lambda (stx) (syntax-arm stx insp))))
|
(lambda (stx) (syntax-arm stx insp))))
|
||||||
|
|
||||||
(define-syntax (def-go stx)
|
(define-syntax (def-go stx)
|
||||||
(syntax-case stx ()
|
(syntax-case stx ()
|
||||||
[(_ go)
|
[(_ go)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user