diff --git a/pkgs/racket-doc/scribblings/reference/syntax-util.scrbl b/pkgs/racket-doc/scribblings/reference/syntax-util.scrbl index 50a482d9e6..4a14acbf3e 100644 --- a/pkgs/racket-doc/scribblings/reference/syntax-util.scrbl +++ b/pkgs/racket-doc/scribblings/reference/syntax-util.scrbl @@ -141,13 +141,15 @@ the parameter has a non-false value. This is done automatically by forms like @racket[with-disappeared-uses]. } -@defform[(with-disappeared-uses stx-expr) +@defform[(with-disappeared-uses body-expr ... stx-expr) #:contracts ([stx-expr syntax?])]{ -Evaluates the @racket[stx-expr], catching identifiers looked up using -@racket[syntax-local-value/record]. Adds the caught identifiers to the -@racket['disappeared-uses] syntax property of the resulting syntax -object. +Evaluates the @racket[body-expr]s and @racket[stx-expr], catching identifiers +looked up using @racket[syntax-local-value/record]. Adds the caught identifiers +to the @racket['disappeared-uses] syntax property of the syntax object produced +by @racket[stx-expr]. + +@history[#:changed "6.5.0.7" @elem{Added the option to include @racket[body-expr]s.}] } @defproc[(syntax-local-value/record [id identifier?] [predicate (-> any/c boolean?)]) @@ -162,14 +164,19 @@ does not satisfy the predicate, @racket[#f] is returned and the identifier is not recorded as a disappeared use. } -@defproc[(record-disappeared-uses [ids (listof identifier?)]) +@defproc[(record-disappeared-uses [id (or/c identifier? (listof identifier?))]) void?]{ -Add @racket[ids] to @racket[(current-recorded-disappeared-uses)] after calling -@racket[syntax-local-introduce] on each of the identifiers. +Add @racket[id] to @racket[(current-recorded-disappeared-uses)] after calling +@racket[syntax-local-introduce] on the identifier. If @racket[id] is a list, +perform the same operation on all the identifiers. If not used within the extent of a @racket[with-disappeared-uses] form or similar, has no effect. + +@history[#:changed "6.5.0.7" + @elem{Added the option to pass a single identifier instead of + requiring a list.}] } diff --git a/racket/collects/racket/syntax.rkt b/racket/collects/racket/syntax.rkt index 8c19c0e936..af8c5c6412 100644 --- a/racket/collects/racket/syntax.rkt +++ b/racket/collects/racket/syntax.rkt @@ -62,10 +62,10 @@ (define current-recorded-disappeared-uses (make-parameter #f)) -(define-syntax-rule (with-disappeared-uses stx-expr) +(define-syntax-rule (with-disappeared-uses body-expr ... stx-expr) (let-values ([(stx disappeared-uses) (parameterize ((current-recorded-disappeared-uses null)) - (let ([result stx-expr]) + (let ([result (let () body-expr ... stx-expr)]) (values result (current-recorded-disappeared-uses))))]) (syntax-property stx 'disappeared-use @@ -88,18 +88,20 @@ value)))) (define (record-disappeared-uses ids) - (unless (and (list? ids) (andmap identifier? ids)) - (raise-argument-error 'record-disappeared-uses - "(listof identifier?)" - ids)) - (let ([uses (current-recorded-disappeared-uses)]) - (when uses - (current-recorded-disappeared-uses - (append - (if (syntax-transforming?) - (map syntax-local-introduce ids) - ids) - uses))))) + (cond + [(identifier? ids) (record-disappeared-uses (list ids))] + [(and (list? ids) (andmap identifier? ids)) + (let ([uses (current-recorded-disappeared-uses)]) + (when uses + (current-recorded-disappeared-uses + (append + (if (syntax-transforming?) + (map syntax-local-introduce ids) + ids) + uses))))] + [else (raise-argument-error 'record-disappeared-uses + "(or/c identifier? (listof identifier?))" + ids)])) ;; == Identifier formatting ==