12.3 Syntax Object Bindings
procedure
(bound-identifier=? a-id b-id [phase-level]) → boolean?
a-id : syntax? b-id : syntax?
phase-level : (or/c exact-integer? #f) = (syntax-local-phase-level)
> (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) 'binds
> (check a b) 'no-binds
> (define-syntax-rule (check-a x) (check a x)) > (check-a a) 'no-binds
procedure
(free-identifier=? a-id b-id [ a-phase-level b-phase-level]) → boolean? a-id : identifier? b-id : identifier?
a-phase-level : (or/c exact-integer? #f) = (syntax-local-phase-level) b-phase-level : (or/c exact-integer? #f) = a-phase-level
“Same module binding” means that the identifiers refer to the same original definition site, and not necessarily to the same require or provide site. Due to renaming in require and provide, or due to a transformer binding to a rename transformer, the identifiers may return distinct results with syntax-e.
> (define-syntax (check stx) (syntax-case stx () [(_ x) (if (free-identifier=? #'car #'x) #'(list 'same: x) #'(list 'different: x))])) > (check car) '(same: #<procedure:car>)
> (check mcar) '(different: #<procedure:mcar>)
> (let ([car list]) (check car)) '(different: #<procedure:list>)
> (require (rename-in racket/base [car kar])) > (check kar) '(same: #<procedure:car>)
procedure
(free-transformer-identifier=? a-id b-id) → boolean?
a-id : identifier? b-id : identifier?
procedure
(free-template-identifier=? a-id b-id) → boolean?
a-id : identifier? b-id : identifier?
procedure
(free-label-identifier=? a-id b-id) → boolean?
a-id : identifier? b-id : identifier?
procedure
(check-duplicate-identifier ids) → (or/c identifier? #f)
ids : (listof identifier?)
procedure
(identifier-binding id-stx [ phase-level top-level-symbol?])
→
(or/c 'lexical #f (list/c module-path-index? symbol? module-path-index? symbol? exact-nonnegative-integer? (or/c exact-integer? #f) (or/c exact-integer? #f)) (list/c symbol?)) id-stx : identifier?
phase-level : (or/c exact-integer? #f) = (syntax-local-phase-level) top-level-symbol? : any/c = #f
The result is 'lexical if id-stx has a local binding.
The result is a list of seven items when id-stx has a module binding: (list from-mod from-sym nominal-from-mod nominal-from-sym from-phase import-phase nominal-export-phase).
from-mod is a module path index (see Compiled Modules and References) that indicates the defining module. It is the “self” module path index if the binding refers to a definition in the enclosing module of id-stx.
from-sym is a symbol for the identifier’s name at its definition site in the originating module. This can be different from the local name returned by syntax->datum for several reasons: the identifier is renamed on import, it is renamed on export, or it is implicitly renamed because the binding site was generated by a macro invocation. In that last case, it may be an unreadable symbol, and it may be different from the result of syntax->datum on the identifier in the original source definition.
nominal-from-mod is a module path index (see Compiled Modules and References) that indicates the binding’s module as it appears locally in the source around id-stx: it indicates a module required into the context of id-stx to provide its binding, or it is the same “self” as from-mod for a binding that refers to a definition in the enclosing module of id-stx. It can be different from from-mod due to a re-export in nominal-from-mod of some imported identifier. If the same binding is imported in multiple ways, an arbitrary representative is chosen.
nominal-from-sym is a symbol for the binding’s identifier as it appears locally in the source around id-stx: it is the identifier’s name as exported by nominal-from-mod, or it is the source identifier’s symbol for a definition within the enclosing module of id-stx. It can be different from from-sym due to a renaming provide, even if from-mod and nominal-from-mod are the same, or due to a definition that was introduced by a macro expansion.
from-phase is an exact non-negative integer representing the originating phase. For example, it is 1 if the definition is for-syntax.
import-phase is 0 if the binding import of nominal-from-mode is from a definition or a plain require, 1 if it is from a for-syntax import, etc.
nominal-export-phase is the phase level of the export from nominal-from-mod for an imported binding or the phase level of the definition for a binding from the enclosing module of id-stx.
The result is (list top-sym) if id-stx has a top-level binding and top-level-symbol? is true. The top-sym can different from the name returned by syntax->datum when the binding definition was generated by a macro invocation.
The result is #f if id-stx has a top-level binding and top-level-symbol? is #f or if id-stx is unbound. An unbound identifier is typically treated the same as an identifier whose top-level binding is a variable.
If id-stx is bound to a rename-transformer, the result from identifier-binding is for the identifier in the transformer, so that identifier-binding is consistent with free-identifier=?.
Changed in version 6.6.0.4 of package base: Added the top-level-symbol? argument to report information on top-level bindings.
procedure
(identifier-transformer-binding id-stx [ rt-phase-level])
→
(or/c 'lexical #f (listof module-path-index? symbol? module-path-index? symbol? exact-nonnegative-integer? (or/c exact-integer? #f) (or/c exact-integer? #f))) id-stx : identifier?
rt-phase-level : (or/c exact-integer? #f) = (syntax-local-phase-level)
procedure
(identifier-template-binding id-stx)
→
(or/c 'lexical #f (listof module-path-index? symbol? module-path-index? symbol? exact-nonnegative-integer? (or/c exact-integer? #f) (or/c exact-integer? #f))) id-stx : identifier?
procedure
(identifier-label-binding id-stx)
→
(or/c 'lexical #f (listof module-path-index? symbol? module-path-index? symbol? exact-nonnegative-integer? (or/c exact-integer? #f) (or/c exact-integer? #f))) id-stx : identifier?
procedure
(identifier-binding-symbol id-stx [ phase-level]) → symbol? id-stx : identifier?
phase-level : (or/c exact-integer? #f) = (syntax-local-phase-level)
When identifier-binding would produce a list, then the second element of that list is the result that identifier-binding-symbol produces.