Next: expander examples contours datum, Previous: expander examples contours single, Up: expander examples contours [Index]
Let’s create two nested lexical contours with the syntax
internal-body
and inspect the rib
objects:
(internal-body (define A 1) (internal-body (define B 2) (begin-for-syntax (pretty-print #'A) (pretty-print #'B) (pretty-print (eq-ribs? #'A #'B)) (pretty-print (length (xp::stx-rib* #'A))) (pretty-print (id-rib*/no-top #'A))) (void))) -| #<syntactic-identifier expr=A mark*=(src)> -| #<syntactic-identifier expr=B mark*=(src)> -| #t -| 3 -| (#<rib name*=(B) mark**=((src)) label*=(lab.B)> #<rib name*=(A) mark**=((src)) label*=(lab.A)>)
we see that:
#'A
and #'B
have the same marks and rib
objects.
#'A
and #'B
build identifiers whose list of rib
objects
has 3 items: the rib
of the internal internal-body
;
the rib
of the external internal-body
; the top rib
, which
we have cut out using id-rib*/no-top
.
rib
of the internal internal-body
comes first in the
list of rib
objects and it has the tuple of ‘B’.
rib
of the external internal-body
comes second in the
list of rib
objects and it has the tuple of ‘A’.
It is simple to resolve the identifiers:
(internal-body (define A 1) (internal-body (define B 2) (begin-for-syntax (pretty-print (id->label #'A)) (pretty-print (id->label #'B)) (pretty-print (id->descriptor #'A)) (pretty-print (id->descriptor #'B))) (void))) -| lab.A -| lab.B -| (lexical . (lex.A . #f)) -| (lexical . (lex.B . #f))
Now let’s create two syntactic bindings with the same source name:
(internal-body (define A 1) (internal-body (define A 2) (begin-for-syntax (pretty-print #'A) (pretty-print (length (xp::stx-rib* #'A))) (pretty-print (id-rib*/no-top #'A))) (void))) -| #<syntactic-identifier expr=A mark*=(src)> -| 3 -| (#<rib name*=(A) mark**=((src)) label*=(lab.A.2)> #<rib name*=(A) mark**=((src)) label*=(lab.A.1)>)
we see that both the rib
objects in the list of ‘#'A’ have a
tuple with source–name ‘A’ and marks ‘(src)’, but the rib
of the internal internal-body
comes first; so the internal
syntactic binding for ‘A’ is the one that captures the identifier:
(internal-body (define A 1) (internal-body (define A 2) (begin-for-syntax (pretty-print (id->label #'A))) (void))) -| lab.A.2
Without describing how macros work, let’s see how we can introduce in the internal body a syntactic identifier that is captured by the external syntactic binding:
(internal-body (define A 1) (define-syntax (doit stx) #'A) (internal-body (define A 2) (pretty-print (doit)))) -| 1
Next: expander examples contours datum, Previous: expander examples contours single, Up: expander examples contours [Index]