difference between free-identifier=? and bound-identifier=?
Asked Answered
D

1

12

Trying to understand free-identifier=? and bound-identifier=?. Can anyone give me equivalent code examples where using free-identifier=? would return true and using bound-identifier=? would return false.

Thanks

Demagnetize answered 23/7, 2011 at 15:43 Comment(3)
See this email on the Racket mailing list, and the surrounding thread.Amesace
I understand what these functions should be used for, and I understand why they are defined the way they are (in terms of marks and substitutions). What I'm having trouble grasping is the circumstances in which they can give different results. A code example (even if fairly meaningless) would help with that.Demagnetize
Your best bet is to ask on the racket list. Ryan will probably answer then. (He's on SO too, but is more likely to miss it here, I'll ping him just in case.)Amesace
H
6

Here's an example:

(define-syntax (compare-with-x stx)
  (syntax-case stx ()
    [(_ x-in)
     (with-syntax ([free=? (free-identifier=? #'x-in #'x)]
                   [bound=? (bound-identifier=? #'x-in #'x)])
       #'(list free=? bound=?))]))

(define-syntax go
  (syntax-rules ()
    [(go) (compare-with-x x)]))

(go) ;; => '(#t #f)

The x introduced by go has a mark from that expansion step on it, but the x in compare-with-x doesn't, so bound-identifier=? considers them different.

Here's another example:

(define-syntax (compare-xs stx)
  (syntax-case stx ()
    [(_ x1 x2)
     (with-syntax ([free=? (free-identifier=? #'x1 #'x2)]
                   [bound=? (bound-identifier=? #'x1 #'x2)])
       #'(list free=? bound=?))]))

(define-syntax go2
  (syntax-rules ()
    [(go2 x-in) (compare-xs x-in x)]))

(go2 x) ;; => '(#t #f)

Here go2 also introduces an x with a mark, whereas the x given to go2 as an argument does not have a mark. Same story.

Hankow answered 27/7, 2011 at 23:29 Comment(1)
Note that (compare-with-x x) also has the result '(#t #f) . The go macro is thus not needed for the first example.Jepum

© 2022 - 2024 — McMap. All rights reserved.