[<<][staapl][>>][..]
Mon Mar 24 10:33:01 EDT 2008

lexical syntax annotation

still i don't fully grasp the notion of lexical information in
syntax. the macros 'let' and 'lambda' annotate syntax with lexical
properties, when they are expanding. so does this work?


(define (make-expr body)
   #`(lambda (x) #,body))
((eval (make-expr #'x)) 123)

=> 123

so it looks like indeed, building syntax like that does perform
'capture'.

my problem is this

(define (wrap stuff)
   #`(lambda (x) #,(stuff #'x)))

(define (stuff stx)
   #`(let ((x 123)) #,stx))

(eval ((wrap stuff) 1))

=> 123

so the inner let captures the #'x
there's nothing special about defining the formal parameter x and the
reference x in the same function 'wrap'.



(define (test-stx stx)
  (syntax-case stx ()
     ((_ (a) b)
      (bound-identifier=? #'a #'b))))

(test-stx #'(lambda (x) x)) => #t

so 'bound-identifier=?' does do some lookup: it doesn't need to expand
the syntax?

EDIT:

what i wonder is: is it possible to construct a function 'wrap' as
above which can guarantee that the 'x doesn't get captured? this
requires some kind of symbol rename.

looks like it's a legitimate question:

(define (wrap stuff)
  (let ((x (car (generate-temporaries #'(x)))))
    #`(lambda (#,x) #,(stuff x))))

(define (stuff stx)
  #`(let ((x 123)) #,stx))

these are constructed using interned symbols, not gensyms. let's
update the lambda code.

so what about syntax marks? 2.3.5

(define-for-syntax (wrap stuff)
  #`(lambda (x)
      #,(syntax-local-introduce
         (stuff (syntax-local-introduce #'x)))))
(define-for-syntax (stuff stx)
  #`(let ((x 123)) #,stx))
(define-syntax (test stx)
  (wrap stuff))

((test) 456)
=> 456

works..  so, if i understand: marking is an on/off operation: the net
result is that syntax introduced by the transformer is marked, and
thus not the same as syntax introduced elsewhere.

EDIT: this does give problems with names introduced by 'letrec-ns'
separately: they are no longer catched. so.. in the end, i'm better of
doing everything non-hygienically? sounds like not right..



[Reply][About]
[<<][staapl][>>][..]