Previous: , Up: expander examples contours   [Index]


15.8.3.3 What datum->syntax does

Armed with our understanding of lists of rib objects as representation of nested lexical contours, we can understand what the standard procedure datum->syntax does (see datum->syntax). Let’s see this example:

(internal-body
  (define A 1)
  (begin-for-syntax
    (define B.id (datum->syntax #'A 'B))
    (pretty-print #'A)
    (pretty-print B.id)
    (pretty-print (eq-ribs? #'A B.id)))
  (void))
-| #<syntactic-identifier expr=A mark*=(src)>
-| #<syntactic-identifier expr=B mark*=(src)>
-| #t

datum->syntax builds a new <stx> using its datum argument as symbolic expression and the marks and rib list of its template-id argument as wraps.

datum->syntax does not care if it generates a syntax objects with unbound identifiers in reference position:

(internal-body
  (define A 1)
  (begin-for-syntax
    (define B.id (datum->syntax #'A 'B))
    (pretty-print (id->label      B.id))
    (pretty-print (id->descriptor B.id)))
  (void))
-| #f
-| (displaced-lexical . ())

it is only if we use the generated syntax object as part of the output form of a macro use that the “boundness” matters.