In the following code, (make-syntax-delta-introducer a b) and 
(make-syntax-delta-introducer b a) have scopes in common (#(8979 module) and 
#(8980 module m 0)), which are part of both inputs. The docs do not mention 
that some scopes present in both `a` and `b` can be part of the resulting 
introducer too. What is causing this behaviour?

#lang racket

(define-syntax (foo stx1)
  (syntax-case stx1 ()
    [(_ name)
     #`(define-syntax (name stx2)
         (let* ([a (datum->syntax (quote-syntax #,stx1) 'x)]
                [b (datum->syntax (quote-syntax #,(syntax-local-introduce 
stx1)) 'y)]
                [delta-a-b (make-syntax-delta-introducer a b)]
                [delta-b-a (make-syntax-delta-introducer b a)])
           (display "a           ") (displayln (hash-ref (syntax-debug-info a) 
'context))
           (display "b           ") (displayln (hash-ref (syntax-debug-info b) 
'context))
           (display "delta a b   ") (displayln (hash-ref (syntax-debug-info 
(delta-a-b (datum->syntax #f 'x) 'add)) 'context))
           (display "delta b a   ") (displayln (hash-ref (syntax-debug-info 
(delta-b-a (datum->syntax #f 'x) 'add)) 'context))
           #'(void)))]))

(foo bar)
(bar)

=>

a           (#(8979 module) #(8980 module m 0) #(8993 use-site))
b           (#(8979 module) #(8980 module m 0) #(8992 macro))
delta a b   (#(8979 module) #(8980 module m 0) #(8993 use-site))
delta b a   (#(8979 module) #(8980 module m 0) #(8992 macro))



It seems that `make-syntax-delta-introducer` reliably gives an introducer 
encapsulating the set of scopes `a - b` only if `b` is the empty set. Based on 
this, I wrote the following function, which seems reliably produce an 
introducer for `a - b`:

(define (scopes-delta a b)
  (let* ([+a (make-syntax-delta-introducer (datum->syntax a 'first)
                                           (datum->syntax #f 'none))]
         [+b (make-syntax-delta-introducer (datum->syntax b 'second)
                                           (datum->syntax #f 'none))]
         [a-b (+b (+a (datum->syntax #f 'none)
                      'add)
                  'remove)])
    (make-syntax-delta-introducer a-b
                                  (datum->syntax #f 'none))))

Georges Dupéron

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to