Skip to content

Instantly share code, notes, and snippets.

@DanielCollins
Created November 13, 2014 02:13
Show Gist options
  • Save DanielCollins/19901dd61263f0dd49ec to your computer and use it in GitHub Desktop.
Save DanielCollins/19901dd61263f0dd49ec to your computer and use it in GitHub Desktop.
(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