Next: , Previous: , Up: iklib syntaxes   [Index]


6.8.20 Syntactic binding properties

It is sometimes useful to attach properties to syntactic bindings; the following API does so. The following functions will fail if the argument id is not a bound identifier.

Function: syntactic-binding-putprop id key value

Like putprop for symbols, but set a property for the identifier id. key must be a symbol; value can be any values. Return unspecified values.

Function: syntactic-binding-getprop id key

Like getprop for symbols, but retrieve a property for the identifier id. key must be a symbol. Return the property value or #f if the property is not set.

Function: syntactic-binding-remprop id key

Like remprop for symbols, but remove a property for the identifier id; nothing happens if the property is not set. key must be a symbol. Return unspecified values.

Function: syntactic-binding-property-list id

Like property-list for symbols, but retrieve the property list for the identifier id. Return the property list or null if no property is set.

We have to remember that when evaluating the syntax:

(define-syntax ?lhs ?rhs)

the identifier ?lhs is already bound when the expression ?rhs is evaluated to acquire the transformer function; the same happens for:

(letrec-syntax ((?lhs ?rhs))
  ?body)

but it does not happen for:

(let-syntax ((?lhs ?rhs))
  ?body)

when the expression ?rhs is evaluated, the identifier ?lhs is still unbound.

So the following example will work:

(define-syntax ciao
  (let ()
    (syntactic-binding-putprop #'ciao 'a 123)
    (lambda (stx) #t)))

(define-syntax (doit stx)
  (syntactic-binding-getprop #'ciao 'a))

(doit)          ⇒ 123

notice that here the syntax ciao is never used; the following example will also work:

(define-syntax (ciao stx)
  #t)

(define-syntax (doit stx)
  (syntactic-binding-getprop #'ciao 'a))

(begin-for-syntax
  (syntactic-binding-putprop #'ciao 'a 123))

(doit)          ⇒ 123

and the following will work, too:

(letrec-syntax
    ((ciao (let ()
             (syntactic-binding-putprop #'ciao 'a 123)
             (lambda (stx) #t))))
  (define-syntax (doit stx)
    (syntactic-binding-getprop #'ciao 'a))
  (doit))
⇒ 123

to define a binding property for a syntax defined by let-syntax we can do:

(let-syntax ((ciao (lambda (stx) #t)))
  (define-syntax (doit stx)
    (syntactic-binding-getprop #'ciao 'a))
  (begin-for-syntax
    (syntactic-binding-putprop #'ciao 'a 123))
  (doit))
⇒ 123

To define a binding property for a lexical variable bound by define:

(define ciao "ciao")

(define-syntax (doit stx)
  (syntactic-binding-getprop #'ciao 'a))

(begin-for-syntax
  (syntactic-binding-putprop #'ciao 'a 123))

(doit)          ⇒ 123

and for one bound by let:

(let ((ciao "ciao"))
  (define-syntax (doit stx)
    (syntactic-binding-getprop #'ciao 'a))
  (begin-for-syntax
    (syntactic-binding-putprop #'ciao 'a 123))
  (doit))
⇒ 123

Next: , Previous: , Up: iklib syntaxes   [Index]