#t
#t
#t
#t
#f
'(#<syntax:eval:14:0 a>
#<syntax:eval:14:0 b>
#<syntax:eval:14:0 c>
#<syntax:eval:14:0 d>)
'(#<syntax:eval:15:0 (a b)> #<syntax:eval:15:0 (c d)>)
'(#<syntax:eval:16:0 a> #<syntax:eval:16:0 b> #<syntax:eval:16:0 (c d)>)
'(#<syntax:eval:17:0 a> #<syntax:eval:17:0 b>)
#f
proc:procedure?stxl:stx-list?
'(#t #f #f #f)
procedure
( module-or-top-identifier=? a-idb-id)→boolean?
a-id:identifier?b-id:identifier?
This procedure is useful in conjunction with syntax-case* to match procedure names that are normally bound by Racket. For example, the include macro uses this procedure to recognize build-path ; using free-identifier=? would not work well outside of module , since the top-level build-path is a distinct variable from the racket/base export (though it’s bound to the same procedure, initially).
syntax
( kernel-syntax-case stx-exprtrans?-exprclause...)
The trans?-expr boolean expression replaces the comparison procedure, and instead selects simply between normal-phase comparisons or transformer-phase comparisons. The clauses are the same as in syntax-case* .
The primitive syntactic forms must have their normal bindings in the context of the kernel-syntax-case expression. Beware that kernel-syntax-case does not work in a module whose language provides different bindings for these primitive syntactic forms, such as mzscheme which does not provide the primitive if and typed/racket which does not provide the primitive let-values among others.
syntax
( kernel-syntax-case* stx-exprtrans?-expr(extra-id...)clause...)
syntax
( kernel-syntax-case/phase stx-exprphase-exprclause...)
syntax
clause...)
procedure
In addition to the identifiers listed in Fully Expanded Programs, the list includes letrec-syntaxes+values , which is the core form for local expand-time binding and can appear in the result of local-expand .
Changed in version 6.90.0.27 of package base: Added quote-syntax and #%plain-module-begin to the list, which had previously been unintentionally missing.
This module provides two implementations of identifier tables: dictionaries with identifier keys that use identifier-specific comparisons instead of eq? or equal? . Identifier tables implement the racket/dict interface, and they are available in both mutable and immutable variants.
A free-identifier table is a dictionary whose keys are compared using free-identifier=? . Free-identifier tables implement the dictionary interface of racket/dict, so all of the appropriate generic functions (dict-ref , dict-map , etc) can be used on free-identifier tables.
A caveat for using these tables is that a lookup can fail with unexpected results if the binding of an identifier changes between key-value insertion and the lookup.
For example, consider the following use:
;set table entry to #t;sanity check, it's set to #t;might expect to get #t, but prints #f> (m)#t
#f
The macro m expands to code that initializes an identifier table at compile-time and inserts a key-value pair for #'x and #t. The #'x identifier has no binding, however, until the definition (define x'defined-now) is evaluated.
As a result, the lookup at the end of m will return #f instead of #t because the binding symbol for #'x changes after the initial key-value pair is put into the table. If the definition is evaluated before the initial insertion, both expressions will print #t.
procedure
procedure
#:phasephase])
The identifiers are compared at phase level phase. The default phase, (syntax-local-phase-level ), is generally appropriate for identifier tables used by macros, but code that analyzes fully-expanded programs may need to create separate identifier tables for each phase of the module.
The optional init-dict argument provides the initial mappings. It must be a dictionary, and its keys must all be identifiers. If the init-dict dictionary has multiple distinct entries whose keys are free-identifier=? , only one of the entries appears in the new id-table, and it is not specified which entry is picked.
procedure
( free-id-table? v)→boolean?
v:any/c
procedure
v:any/c
procedure
v:any/c
procedure
( free-id-table-ref tableid[failure])→any
table:free-id-table?id:identifier?
procedure
( free-id-table-ref! tableidfailure)→any
table:mutable-free-id-table?id:identifier?failure:any/c
Added in version 6.3.0.6 of package base.
procedure
( free-id-table-set! tableidv)→void?
table:mutable-free-id-table?id:identifier?v:any/c
procedure
( free-id-table-set tableidv)→immutable-free-id-table?
table:immutable-free-id-table?id:identifier?v:any/c
procedure
( free-id-table-set*! tableidv......)→void?
table:mutable-free-id-table?id:identifier?v:any/c
Added in version 6.3.0.6 of package base.
procedure
( free-id-table-set* tableidv......)→immutable-free-id-table?
table:immutable-free-id-table?id:identifier?v:any/c
Added in version 6.3.0.6 of package base.
procedure
( free-id-table-remove! tableid)→void?
table:mutable-free-id-table?id:identifier?
procedure
( free-id-table-remove tableid)→immutable-free-id-table?
table:immutable-free-id-table?id:identifier?
procedure
idupdatertable:mutable-free-id-table?id:identifier?
Added in version 6.3.0.6 of package base.
procedure
idupdatertable:immutable-free-id-table?id:identifier?
Added in version 6.3.0.6 of package base.
procedure
( free-id-table-map tableproc)→list?
table:free-id-table?
procedure
( free-id-table-keys table)→(listof identifier? )
table:free-id-table?
Added in version 6.3.0.3 of package base.
procedure
( free-id-table-values table)→(listof any/c )
table:free-id-table?
Added in version 6.3.0.3 of package base.
procedure
( in-free-id-table table)→sequence?
table:free-id-table?
Added in version 6.3.0.3 of package base.
procedure
( free-id-table-for-each tableproc)→void?
table:free-id-table?
procedure
table:free-id-table?
procedure
table:free-id-table?procedure
( free-id-table-iterate-next tableposition)→id-table-iter?
table:free-id-table?position:id-table-iter?procedure
( free-id-table-iterate-key tableposition)→identifier?
table:free-id-table?position:id-table-iter?
procedure
( id-table-iter? v)→boolean?
v:any/c
procedure
val-ctckey-ctc:flat-contract?val-ctc:chaperone-contract?
A bound-identifier table is a dictionary whose keys are compared using bound-identifier=? . Bound-identifier tables implement the dictionary interface of racket/dict, so all of the appropriate generic functions (dict-ref , dict-map , etc) can be used on bound-identifier tables.
procedure
procedure
#:phasephase])procedure
( bound-id-table? v)→boolean?
v:any/cprocedure
v:any/cprocedure
v:any/cprocedure
( bound-id-table-ref! tableidfailure)→any
table:mutable-bound-id-table?id:identifier?failure:any/cprocedure
( bound-id-table-set*! tableidv......)→void?
table:mutable-bound-id-table?id:identifier?v:any/cprocedure
( bound-id-table-remove tableid)→immutable-bound-id-table?
id:identifier?procedure
idupdaterid:identifier?procedure
( bound-id-table-map tableproc)→list?
table:bound-id-table?procedure
( bound-id-table-keys table)→(listof identifier? )
table:bound-id-table?procedure
( bound-id-table-values table)→(listof any/c )
table:bound-id-table?procedure
( in-bound-id-table table)→sequence?
table:bound-id-table?procedure
( bound-id-table-for-each tableproc)→void?
table:bound-id-table?procedure
table:bound-id-table?procedure
( bound-id-table-iterate-first table)→id-table-position?
table:bound-id-table?procedure
( bound-id-table-iterate-key tableposition)→identifier?
table:bound-id-table?position:id-table-position?
Changed in version 6.3.0.3 of package base: Added bound-id-table-keys, bound-id-table-values, in-bound-id-table.
Changed in version 6.3.0.6: Added bound-id-table-ref!, bound-id-table-set*,
bound-id-table-set*!, bound-id-table-update!, and bound-id-table-update
This module provides identifier sets: sets with identifier keys that use identifier-specific comparisons instead of the usual equality operators such as eq? or equal? .
This module implements two kinds of identifier sets: one via free-identifier=? and one via bound-identifier=? . Each are available in both mutable and immutable variants and implement the gen:set , gen:stream , prop:sequence , and gen:equal+hash generic interfaces.
Identifier sets are implemented using identifier tables, in the same way that hash sets are implemented with hash tables.
A free-identifier set is a set whose keys are compared using free-identifier=? . Free-identifier sets implement the gen:set interface, so all of the appropriate generic functions (e.g., set-add , set-map , etc) can be used on free-identifier sets.
procedure
procedure
The identifiers are compared at phase level phase. The default phase, (syntax-local-phase-level ), is generally appropriate for identifier sets used by macros, but code that analyzes fully-expanded programs may need to create separate identifier sets for each phase of the module.
The optional init-set argument provides the initial set elements. It must be a set of identifiers. If the init-set set has multiple distinct entries whose keys are free-identifier=? , only one of the entries appears in the new id-set, and it is not specified which entry is picked.
procedure
( free-id-set? v)→boolean?
v:any/c
procedure
v:any/c
procedure
v:any/c
procedure
procedure
procedure
( free-id-set-member? sv)→boolean?
procedure
( free-id-set=? s1s2)→boolean?
s1:free-id-set?s2:free-id-set?
procedure
procedure
( free-id-set-add! sv)→void?
procedure
procedure
( free-id-set-remove! sv)→void?
procedure
procedure
procedure
( in-free-id-set s)→sequence?
procedure
( free-id-set->stream s)→stream?
procedure
( free-id-set->list s)→list?
procedure
procedure
procedure
procedure
( free-id-set-clear! s)→void?
procedure
( free-id-set-union s0s...)→immutable-free-id-set?
procedure
( free-id-set-union! s0s...)→void?
procedure
( free-id-set-intersect s0s...)→immutable-free-id-set?
procedure
( free-id-set-intersect! s0s...)→void?
procedure
( free-id-set-subtract s0s...)→immutable-free-id-set?
procedure
( free-id-set-subtract! s0s...)→void?
procedure
( free-id-set-symmetric-difference s0s...)
procedure
( free-id-set-symmetric-difference! s0s...)→void?
procedure
( free-id-subset? s1s2)→boolean?
s1:free-id-set?s2:free-id-set?
procedure
( free-id-proper-subset? s1s2)→boolean?
s1:free-id-set?s2:free-id-set?
procedure
( free-id-set-map sf)→list?
procedure
( free-id-set-for-each sf)→void?
elem-ctc:flat-contract?= 'immutable
procedure
elem-ctc:flat-contract?= 'immutable
A bound-identifier set is a set whose keys are compared using bound-identifier=? . Bound-identifier sets implement the gen:set interface, so all of the appropriate generic functions (e.g., set-add , set-map , etc.) can be used on bound-identifier sets.
procedure
procedure
#:phasephase])procedure
( bound-id-set? v)→boolean?
v:any/cprocedure
v:any/cprocedure
v:any/cprocedure
procedure
procedure
procedure
procedure
( in-bound-id-set s)→sequence?
procedure
( bound-id-set->stream s)→stream?
procedure
( bound-id-set->list s)→list?
procedure
procedure
procedure
procedure
( bound-id-set-clear! s)→void?
procedure
( bound-id-set-union s0s...)→immutable-bound-id-set?
procedure
procedure
( bound-id-set-subtract s0s...)→immutable-bound-id-set?
procedure
( bound-id-set-symmetric-difference s0s...)
procedure
This library is for backwards-compatibility. Do not use it for new libraries; use syntax/id-table instead.
procedure
procedure
v:any/cprocedure
bound-map:bound-identifier-mapping?procedure
bound-map:bound-identifier-mapping?
procedure
procedure
v:any/cprocedure
( free-identifier-mapping-put! free-mapidv)→void?
free-map:free-identifier-mapping?id:identifier?v:any/cprocedure
free-map:free-identifier-mapping?procedure
( free-identifier-mapping-map free-mapproc)→(listof any?)
free-map:free-identifier-mapping?
procedure
( make-module-identifier-mapping )→module-identifier-mapping?
procedure
v:any/cprocedure
module-map:module-identifier-mapping?procedure
module-map:module-identifier-mapping?
procedure
( syntax->string stx-list)→string?
procedure
[ insp#:module-bound?module-bound?])expr-stx:syntax?
The inspector insp is used to disarm expr-stx and sub-expressions before extracting identifiers. The default insp is the declaration-time inspector of the syntax/free-vars module.
If module-bound? is non-false, the list of free variables also includes free module-bound identifiers.
expanded-body])]))(#<syntax:eval:3:0 x>)
#<procedure>
procedure
( strip-context form)→any/c
form:any/c
Typically, form is a syntax object, and then the result is also a syntax object. Otherwise, pairs, vectors, boxes, hash tables, and prefab structures are traversed (and copied for the result) to find syntax objects. Graph structure is not preserved in the result, and cyclic data structures will cause strip-context to never return.
Changed in version 7.7.0.10 of package base: Repaired to traverse hash tables in stx.
procedure
( replace-context ctx-stxform)→any/c
form:any/c
Syntax objects are found in form the same as in strip-context .
Changed in version 7.7.0.10 of package base: Repaired to traverse hash tables in stx.
The syntax/keyword module contains procedures for parsing keyword options in macros.
A keyword-table is a dictionary (dict? ) mapping keywords to lists of check-procedures. (Note that an association list is a suitable dictionary.) The keyword’s arity is the length of the list of procedures.
A check procedure consumes the syntax to check and a context syntax object for error reporting and either raises an error to reject the syntax or returns a value as its parsed representation.
stx)
Parsed options are represented as an list of option entries. Each entry contains the keyword, the syntax of the keyword (for error reporting), and the list of parsed values returned by the keyword’s list of check procedures. The list contains the parsed options in the order they appeared in the input, and a keyword that occurs multiple times in the input occurs multiple times in the options list.
procedure
table[ #:contextctx#:no-duplicates?no-duplicates?#:incompatibleincompatible#:on-incompatibleincompatible-handler#:on-too-shorttoo-short-handler#:on-not-in-tablenot-in-table-handler])stx:syntax?table:keyword-table
Parsing stops normally when the syntax list does not have a keyword at its head (it may be empty, start with a non-keyword term, or it may be a non-list syntax object). Two values are returned: the parsed options and the rest of the syntax (generally either a syntax object or a list of syntax objects).
A variety of errors and exceptional conditions can occur during the parsing process. The following keyword arguments determine the behavior in those situations.
The #:contextctx argument is used to report all errors in parsing syntax. In addition, ctx is passed as the final argument to all provided handler procedures. Macros using parse-keyword-options should generally pass the syntax object for the whole macro use as ctx.
If no-duplicates? is a non-false value, then duplicate keyword options are not allowed. If a duplicate is seen, the keyword’s associated check procedures are not called and an incompatibility is reported.
The incompatible argument is a list of incompatibility entries, where each entry is a list of at least two keywords. If any keyword in the entry occurs after any other keyword in the entry, an incompatibility is reported.
Note that including a keyword in an incompatibility entry does not prevent it from occurring multiple times. To disallow duplicates of some keywords (as opposed to all keywords), include those keywords in the incompatible list as being incompatible with themselves. That is, include them twice:
;Disallow duplicates of only the #:foo keyword
When an incompatibility occurs, the incompatible-handler is tail-called with the two keywords causing the incompatibility (in the order that they occurred in the syntax list, so the keyword triggering the incompatibility occurs second), the syntax list starting with the occurrence of the second keyword, and the context (ctx). If the incompatibility is due to a duplicate, the two keywords are the same.
When a keyword is not followed by enough arguments according to its arity in table, the too-short-handler is tail-called with the keyword, the options parsed thus far, the syntax list starting with the occurrence of the keyword, and ctx.
When a keyword occurs in the syntax list that is not in table, the not-in-table-handler is tail-called with the keyword, the options parsed thus far, the syntax list starting with the occurrence of the keyword, and ctx.
Handlers typically escape—all of the default handlers raise errors—but if they return, they should return two values: the parsed options and a syntax object; these are returned as the results of parse-keyword-options .
'((#:transparent #<syntax:eval:4:0 #:transparent>)
(#:property
#<syntax:eval:4:0 #:property>
#<syntax:eval:4:0 p>
#<syntax:eval:4:0 (lambda (x) (f x))>))
'()
#:incompatible'((#:transparent#:inspector)(#:inspector#:inspector)(#:inspector#:inspector)))define-struct: #:inspector option not allowed after
#:transparent option
procedure
stxtable[ #:contextctx#:no-duplicates?no-duplicates?#:incompatibleincompatible#:on-incompatibleincompatible-handler#:on-too-shorttoo-short-handler#:on-not-in-tablenot-in-table-handler#:on-not-eolnot-eol-handler])stx:syntax?table:keyword-table
procedure
( options-select optionskeyword)→(listof list? )
options:optionskeyword:keyword?
procedure
( check-identifier stxctx)→identifier?
stx:syntax?
procedure
( check-expression stxctx)→syntax?
stx:syntax?
procedure
(( check-stx-listof check)stxctx)→(listof any/c )
check:check-procedurestx:syntax?
procedure
( check-stx-string stxctx)→syntax?
stx:syntax?
procedure
( check-stx-boolean stxctx)→syntax?
stx:syntax?