Next: expander examples contours, Previous: expander examples intro, Up: expander examples [Index]
The syntactic bindings established by the import
clause of
programs and libraries are stored in a rib
object; this rib
represents the top–level environment and it is referred to as
top–level rib
. The descriptors of top–level syntactic
bindings are stored in the value
field of their label gensyms.
We can look at a syntactic identifier as follows:
(begin-for-syntax (pretty-print #'display)) -| #<syntactic-identifier expr=display mark*=(src)>
we see that: the source–name symbol is ‘display’; the list of
marks is ‘(src)’; the list of rib
objects is not displayed,
because it is too long. We can inspect the list of rib
objects too:
(begin-for-syntax (pretty-print (xp::stx-rib* #'display))) -| (#<rib name*=(...) mark**=(...) label*=(...) sealed/freq=#f>)
we do not show the full output, because it is really long: the list of
ribs contains a single item being the top–level rib
of the program;
this top rib
contains a tuple for every syntactic binding imported in
the program.
We can retrieve the elements of syntactic bindings from the top rib
:
(begin-for-syntax (pretty-print (id->label #'display))) -| lab.display (begin-for-syntax (pretty-print (id->descriptor #'display))) -| (core-prim . display)
If we define a lexical variable at the top–level of the program, we can then query its syntactic binding:
(define A 1) (begin-for-syntax (pretty-print (id->label #'A)) (pretty-print (id->descriptor #'A))) -| lab.A -| (lexical . (lex.A . #f))
In the following examples: we avoid defining top–level bindings because
printing the top rib
is annoying; for this reason we use the function
id-rib*/no-top
which cuts out the top rib
from a list of
rib
objects (the top rib
is always the last item in a list of
ribs).
Next: expander examples contours, Previous: expander examples intro, Up: expander examples [Index]