Skip to content

Instantly share code, notes, and snippets.

@dyoo
Created May 15, 2013 20:24
Show Gist options
  • Save dyoo/5587061 to your computer and use it in GitHub Desktop.
Save dyoo/5587061 to your computer and use it in GitHub Desktop.
example of equal?/recur that deals with cycles.
#lang racket/base
(require data/union-find)
(define (equal?/id x y)
(define ufs (make-hasheq))
(let loop ([x x]
[y y])
(cond [(and (identifier? x) (identifier? y))
(free-identifier=? x y)]
[else
(define ux (hash-ref! ufs x (lambda () (uf-new x))))
(define uy (hash-ref! ufs y (lambda () (uf-new y))))
(cond
[(uf-same-set? ux uy)
#t]
[else
(uf-union! ux uy)
(equal?/recur x y loop)])])))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment