revise examples for bound-identifier=? and free-identifier=?
This commit is contained in:
parent
32297601b6
commit
88a06c724c
|
@ -1,6 +1,9 @@
|
||||||
#lang scribble/doc
|
#lang scribble/doc
|
||||||
@(require "mz.ss")
|
@(require "mz.ss")
|
||||||
|
|
||||||
|
@(define stx-eval (make-base-eval))
|
||||||
|
@(interaction-eval #:eval stx-eval (require (for-syntax racket/base)))
|
||||||
|
|
||||||
@title[#:tag "stxcmp"]{Syntax Object Bindings}
|
@title[#:tag "stxcmp"]{Syntax Object Bindings}
|
||||||
|
|
||||||
@defproc[(bound-identifier=? [a-id syntax?] [b-id syntax?]
|
@defproc[(bound-identifier=? [a-id syntax?] [b-id syntax?]
|
||||||
|
@ -14,7 +17,19 @@ suitable expression context at the @tech{phase level} indicated by
|
||||||
@scheme[phase-level], @scheme[#f] otherwise. A @scheme[#f] value for
|
@scheme[phase-level], @scheme[#f] otherwise. A @scheme[#f] value for
|
||||||
@scheme[phase-level] corresponds to the @tech{label phase level}.
|
@scheme[phase-level] corresponds to the @tech{label phase level}.
|
||||||
|
|
||||||
See @scheme[free-identifier=?] for an example.}
|
@examples[
|
||||||
|
#:eval stx-eval
|
||||||
|
(define-syntax (check stx)
|
||||||
|
(syntax-case stx ()
|
||||||
|
[(_ x y)
|
||||||
|
(if (bound-identifier=? #'x #'y)
|
||||||
|
#'(let ([y 'wrong]) (let ([x 'binds]) y))
|
||||||
|
#'(let ([y 'no-binds]) (let ([x 'wrong]) y)))]))
|
||||||
|
(check a a)
|
||||||
|
(check a b)
|
||||||
|
(define-syntax-rule (check-a x) (check a x))
|
||||||
|
(check-a a)
|
||||||
|
]}
|
||||||
|
|
||||||
|
|
||||||
@defproc[(free-identifier=? [a-id syntax?] [b-id syntax?]
|
@defproc[(free-identifier=? [a-id syntax?] [b-id syntax?]
|
||||||
|
@ -36,20 +51,19 @@ to a @tech{rename transformer}, the identifiers may return distinct
|
||||||
results with @scheme[syntax-e].
|
results with @scheme[syntax-e].
|
||||||
|
|
||||||
@examples[
|
@examples[
|
||||||
(require (for-syntax racket/base))
|
#:eval stx-eval
|
||||||
(let ([fred 17])
|
(define-syntax (check stx)
|
||||||
(define-syntax a
|
(syntax-case stx ()
|
||||||
(lambda (x)
|
[(_ x)
|
||||||
(syntax-case x ()
|
(if (free-identifier=? #'car #'x)
|
||||||
[(_ id) #'(b id fred)])))
|
#'(list 'same: x)
|
||||||
(define-syntax b
|
#'(list 'different: x))]))
|
||||||
(lambda (x)
|
(check car)
|
||||||
(syntax-case x ()
|
(check mcar)
|
||||||
[(_ id1 id2)
|
(let ([car list])
|
||||||
#`(list
|
(check car))
|
||||||
#,(free-identifier=? #'id1 #'id2)
|
(require (rename-in racket/base [car kar]))
|
||||||
#,(bound-identifier=? #'id1 #'id2))])))
|
(check kar)
|
||||||
(a fred))
|
|
||||||
]}
|
]}
|
||||||
|
|
||||||
@defproc[(free-transformer-identifier=? [a-id syntax?] [b-id syntax?]) boolean?]{
|
@defproc[(free-transformer-identifier=? [a-id syntax?] [b-id syntax?]) boolean?]{
|
||||||
|
@ -200,3 +214,4 @@ Same as @scheme[(identifier-binding id-stx (sub1 (syntax-local-phase-level)))].}
|
||||||
|
|
||||||
Same as @scheme[(identifier-binding id-stx #f)].}
|
Same as @scheme[(identifier-binding id-stx #f)].}
|
||||||
|
|
||||||
|
@close-eval[stx-eval]
|
||||||
|
|
Loading…
Reference in New Issue
Block a user