Created
May 15, 2013 20:24
-
-
Save dyoo/5587061 to your computer and use it in GitHub Desktop.
example of equal?/recur that deals with cycles.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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