Re: [racket-users] (make-syntax-delta-introducer a b) and (m-s-d-i b a) have scopes in common

2016-07-31 Thread Matthew Flatt
I see that the documentation --- at least a reasonable reading of that
prose --- doesn't match the implementation.

The implementation treats the two arguments as having no scopes in
common if the second is not a subset of the first. Since the scopes on
`a` and `b` are not subsets of each other

 (make-syntax-delta-introducer a b)

counts the full set of `a` scopes as the "delta", while

 (make-syntax-delta-introducer b a)

counts the full set of `b` scopes as the "delta".

The implemented behavior turned out to be useful for implementing
macros that work with identifiers from different modules at once. The
behavior is certainly confusing absent a use case, and it's not
documented correctly, so I'll fix the documentation.


At Sun, 31 Jul 2016 14:11:17 -0700 (PDT), Dupéron Georges wrote:
> 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.

-- 
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.


[racket-users] (make-syntax-delta-introducer a b) and (m-s-d-i b a) have scopes in common

2016-07-31 Thread Dupéron Georges
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.