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

stchang
  • 2,555
  • 15
  • 17
jahhaj
  • 763
  • 4
  • 9
  • See [this email](http://lists.racket-lang.org/users/archive/2011-April/045117.html) on the Racket mailing list, and the surrounding thread. – Eli Barzilay Jul 25 '11 at 04:24
  • 1
    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. – jahhaj Jul 26 '11 at 07:07
  • 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.) – Eli Barzilay Jul 27 '11 at 18:38

1 Answers1

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.

Sorawee Porncharoenwase
  • 6,305
  • 1
  • 14
  • 28
Ryan Culpepper
  • 10,495
  • 4
  • 31
  • 30
  • Note that `(compare-with-x x)` also has the result `'(#t #f)` . The `go` macro is thus not needed for the first example. – soegaard Jun 18 '14 at 18:41