Created
November 13, 2014 02:13
-
-
Save DanielCollins/19901dd61263f0dd49ec to your computer and use it in GitHub Desktop.
This file contains 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
(define (unify a b) | |
(cond ((and (pair? a) | |
(pair? b)) (cons (unify (car a) (car b)) | |
(unify (cdr a) (cdr b)))) | |
((symbol? a) b) ; here i just return b, because a symbol matches anything. a more complex system would have a third argument | |
; , the environment, that tracks existing bindings for a, and prevents conflicts. then, instead of returning b | |
; we could update the environment with the binding for a = b, or issue a failure (in kanren language, #u) | |
((eq? a b) b) ; a and b trivially unify without updating any bindings. here I just return their mutual value | |
(else (error)))) ; nope, that's a #u |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment