Next: , Previous: , Up: expander examples contours   [Index]


15.8.3.2 Double internal body

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:

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: , Previous: , Up: expander examples contours   [Index]