12.9 Expanding Top-Level Forms
Before top-level-form is expanded, its lexical context is enriched with namespace-syntax-introduce, just as for eval. Use syntax->datum to convert the returned syntax object into a printable datum.
Here’s an example of using expand on a module:
(parameterize ([current-namespace (make-base-namespace)]) (expand (datum->syntax #f '(module foo scheme (define a 3) (+ a 4)))))
Here’s an example of using expand on a non-top-level form:
(define-namespace-anchor anchor) (parameterize ([current-namespace (namespace-anchor->namespace anchor)]) (expand (datum->syntax #f '(delay (+ 1 2)))))
procedure
(expand-syntax stx) → syntax?
stx : syntax?
procedure
(expand-once top-level-form) → syntax?
top-level-form : any/c
Before top-level-form is expanded, its lexical context is enriched with namespace-syntax-introduce, as for eval.
procedure
(expand-syntax-once stx) → syntax?
stx : syntax?
procedure
(expand-to-top-form top-level-form) → syntax?
top-level-form : any/c
Before stx-or-sexpr is expanded, its lexical context is enriched with namespace-syntax-introduce, as for eval.
procedure
(expand-syntax-to-top-form stx) → syntax?
stx : syntax?
12.9.1 Information on Expanded Modules
Information for an expanded module declaration is stored in a set of syntax properties (see Syntax Object Properties) attached to the syntax object:
'module-direct-requires —
a list of module path indexes (or symbols) representing the modules explicitly imported into the module. 'module-direct-for-syntax-requires —
a list of module path indexes (or symbols) representing the modules explicitly for-syntax imported into the module. 'module-direct-for-template-requires —
a list of module path indexes (or symbols) representing the modules explicitly for-template imported into the module. 'module-direct-for-meta-requires —
a list of lists: each list is an integer or #f representing a phase level followed by a list of module path indexes (or symbols) representing the modules explicitly imported into the module at the corresponding phase. Added in version 6.4.0.1 of package base.
'module-variable-provides —
a list of provided items, where each item is one of the following: symbol —
represents a locally defined variable that is provided with its defined name. (cons provided-sym defined-sym) —
represents a locally defined variable that is provided with renaming; the first symbol is the exported name, and the second symbol is the defined name. (list* module-path-index provided-sym defined-sym) —
represents a re-exported and possibly re-named variable from the specified module; module-path-index is either a module path index or symbol (see Compiled Modules and References), indicating the source module for the binding. The provided-sym is the external name for the re-export, and defined-sym is the originally defined name in the module specified by module-path-index.
'module-syntax-provides —
like 'module-variable-provides, but for syntax exports instead of variable exports. 'module-indirect-provides —
a list of symbols for variables that are defined in the module but not exported; they may be exported indirectly through macro expansions. Definitions of macro-generated identifiers create uninterned symbols in this list. 'module-body-context —
a syntax object whose lexical information corresponds to the inside of the module, so it includes the expansion’s outside-edge scope and its inside-edge scope; that is, the syntax object simulates an identifier that is present in the original module body and inaccessible to manipulation by any macro, so that its lexical information includes bindings for the module’s imports and definitions. Added in version 6.4.0.1 of package base.
'module-body-inside-context —
a syntax object whose lexical information corresponds to an identifier that starts with no lexical context and is moved into the macro, so that it includes only the expansions’s inside-edge scope. Added in version 6.4.0.1 of package base.
'module-body-context-simple? —
a boolean, where #t indicates that the bindings of the module’s body (as recorded in the lexical information of the value of the 'module-body-inside-context property) can be directly reconstructed from the values of 'module-direct-requires, 'module-direct-for-syntax-requires, 'module-direct-for-template-requires, and 'module-direct-for-meta-requires. Added in version 6.4.0.1 of package base.