procedure
( syntax-local-infer-name stx[use-local?])→any/c
stx:syntax?
To support the propagation and merging of consistent properties during expansions, the value of the 'inferred-name property can be a tree formed with cons where all of the leaves are the same. For example, (cons 'name'name) is equivalent to 'name, and (cons (void )(void )) is equivalent to #<void>.
If use-local? is #f, then syntax-local-name is not used. Provide use-local? as #f to construct a name for a syntax object that is not an expression currently being expanded.
procedure
procedure
( generate-expand-context [liberal-definitions?])→list?
procedure
lambda-id-stx[ check-context?defn-stx:syntax?lambda-id-stx:identifier?
To generate the right-hand side, this function may need to insert uses of lambda . The lambda-id-stx argument provides a suitable lambda identifier.
If the definition is ill-formed, a syntax error is raised. If check-context? is true, then a syntax error is raised if (syntax-local-context ) indicates that the current context is an expression context. The default value of check-context? is #t.
If opt+kws? is #t, then arguments of the form [idexpr], keywordid, and keyword[idexpr] are allowed, and they are preserved in the expansion.
procedure
lambda-id-stxcheck-context?opt+kws?err-no-body?)→defn-stx:syntax?lambda-id-stx:identifier?check-context?:boolean?opt+kws?:boolean?err-no-body?:boolean?
If err-no-body? is true, then there must be a right-hand side expression or else it is a syntax error. The err-no-body? argument is true for uses of normalize-definition .
Added in version 6.1.1.8 of package base.
procedure
( flatten-begin stx)→(listof syntax? )
stx:syntax?
'(#<syntax:eval:2:0 1> #<syntax:eval:2:0 2> #<syntax:eval:2:0 3>)
'(#<syntax:eval:3:0 (begin 1 2)> #<syntax:eval:3:0 3>)
'(#<syntax:eval:4:0 (- 1 2)> #<syntax:eval:4:0 3>)
procedure
( flatten-all-begins stx)→(listof syntax? )
stx:syntax?
'(#<syntax:eval:5:0 1> #<syntax:eval:5:0 2> #<syntax:eval:5:0 3>)
'(#<syntax:eval:6:0 1> #<syntax:eval:6:0 2> #<syntax:eval:6:0 3>)
Added in version 6.1.0.3 of package base.
procedure
stx:syntax?orig-stx:syntax?
procedure
field-ids[ #:constructor-namectr-name]omit-sel?omit-set?[ src-stx])name-id:identifier?omit-sel?:boolean?omit-set?:boolean?
struct:name-id
ctr-name, or make-name-id if ctr-name is #f
name-id?
name-id-field, for each field in field-ids.
set-name-id-field! (getter and setter names alternate).
....
If omit-sel? is true, then the selector names are omitted from the result list. If omit-set? is true, then the setter names are omitted from the result list.
The default src-stx is #f; it is used to provide a source location to the generated identifiers.
procedure
field-ids[ #:constructor-namectr-name]omit-sel?omit-set?[ super-typeprop-value-listimmutable-k-list])name-id:identifier?omit-sel?:boolean?omit-set?:boolean?
procedure
name-idfield-ids[ #:constructor-namectr-name]omit-sel?omit-set?[ super-typeprop-value-listimmutable-k-list])name-id:identifier?omit-sel?:boolean?omit-set?:boolean?
procedure
field-ids[ #:omit-constructor?no-ctr?#:constructor-namectr-name#:omit-struct-type?no-type?]omit-sel?omit-set?base-namebase-gettersname-id:identifier?omit-sel?:boolean?omit-set?:boolean?
If no-ctr? is true, then the constructor name is omitted from the expansion-time information. Similarly, if no-type? is true, then the structure-type name is omitted.
A #t for the base-name means no super-type, #f means that the super-type (if any) is unknown, and an identifier indicates the super-type identifier.
procedure
v:any/c
procedure
name-idsuper-id-or-falsefield-id-listcurrent-contextmake-make-struct-type[ omit-sel?orig-stx:syntax?name-id:identifier?current-context:any/cmake-make-struct-type:procedure?
The generate-struct-declaration procedure is called by a macro expander to generate the expansion, where the name-id, super-id-or-false, and field-id-list arguments provide the main parameters. The current-context argument is normally the result of syntax-local-context . The orig-stx argument is used for syntax errors. The optional omit-sel? and omit-set? arguments default to #f; a #t value suppresses definitions of field selectors or mutators, respectively.
The make-struct-type procedure is called to generate the expression to actually create the struct type. Its arguments are orig-stx, name-id-stx, defined-name-stxes, and super-info. The first two are as provided originally to generate-struct-declaration , the third is the set of names generated by build-struct-names , and the last is super-struct info obtained by resolving super-id-or-false when it is not #f, #f otherwise.
The result should be an expression whose values are the same as the result of make-struct-type . Thus, the following is a basic make-make-struct-type:
0#f))
but an actual make-make-struct-type will likely do more.
The source-stx specifies a syntax object whose source-location information determines relative-path resolution. The expr-stx is used for reporting syntax errors.
procedure
#:savesave-proc#:restore-stxrestore-proc-stx[ #:leaf-saveleaf-save-proc#:leaf-restore-stxleaf-restore-proc-stx#:leaf-datum-stxleaf-datum-proc-stx#:pvar-savepvar-save-proc#:pvar-restore-stxpvar-restore-stx#:cons-stxcons-proc-stx#:ellipses-end-stxellipses-end-stx#:constant-as-leaf?constant-as-leaf?])template-stx:syntax?restore-proc-stx:syntax?
The save-proc is applied to each syntax object in the representation of the original template (i.e., in template-stx). If constant-as-leaf? is #t, then save-proc is applied only to syntax objects that contain at least one pattern variable in a sub-form. The result of save-proc is provided back as the first argument to restore-proc-stx, which indicates a function with a contract (-> any/c syntax any/c any/c ); the second argument to restore-proc-stx is the syntax object that syntax generates, and the last argument is a datum that have been processed recursively (by functions such as restore-proc-stx) and that normally would be converted back to a syntax object using the second argument’s context, source, and properties. Note that save-proc works at expansion time (with respect to the template form), while restore-proc-stx indicates a function that is called at run time (for the template form), and the data that flows from save-proc to restore-proc-stx crosses phases via quote .
The leaf-save-proc and leaf-restore-proc-stx procedures are analogous to save-proc and restore-proc-stx, but they are applied to leaves, so there is no third argument for recursively processed sub-forms. The function indicated by leaf-restore-proc-stx should have the contract (-> any/c syntax? any/c ).
The leaf-datum-proc-stx procedure is applied to leaves that are not syntax objects, which can happen because pairs and the empty list are not always individually wrapped as syntax objects. The function should have the contract (-> any/c any/c ). When constant-as-leaf? is #f, the only possible argument to the procedure is null .
The pvar-save and pvar-restore-stx procedures are analogous to save-proc and restore-proc-stx, but they are applied to pattern variables. The pvar-restore-stx procedure should have the contract (-> any/c syntax? any/c ), where the second argument corresponds to the substitution of the pattern variable.
The cons-proc-stx procedure is used to build intermediate pairs, including pairs passed to restore-proc-stx and pairs that do not correspond to syntax objects.
The ellipses-end-stx procedure is an extra filter on the syntax object that follows a sequence of ... ellipses in the template. The procedure should have the contract (-> any/c any/c ).
The following example illustrates a use of transform-template to implement a syntax/shape form that preserves the 'paren-shape property from the original template, even if the template code is marshaled within bytecode.
'paren-shapev))#:saveget-shape-prop#:restore-stx#'add-shape-prop)]))
procedure
[ setter-stx])
If the macro identifier is used as the target of a set! form, then the set! form expands into the application of setter-stx to the set! expression’s right-hand side, if setter-stx is syntax; otherwise, the identifier is considered immutable and a syntax error is raised. If setter-stx is a procedure, it is applied to the entire set! expression.
> (op5)6
> op0
Added in version 6.3 of package base.
procedure
( make-expression-transformer transformer)
Added in version 7.7.0.9 of package base.
procedure
stxcontextstx:syntax?
Applies transformer as a syntax transformer to stx in the current expansion context. The result is similar to expanding a use of an identifier bound as a syntax transformer bound to transformer with local-expand , except that expansion is guaranteed to stop after applying a single macro transformation (assuming transformer does not explicitly force further recursive expansion).
Unlike simply applying transformer to stx directly, using local-apply-transformer introduces the appropriate use-site scope and macro-introduction scope that would be added by the expander.
The context and intdef-ctx arguments are treated the same way as the corresponding arguments to local-expand .
Added in version 6.90.0.29 of package base.