diff --git a/unify.rkt b/unify.rkt index 77f3fef..e692d0a 100644 --- a/unify.rkt +++ b/unify.rkt @@ -10,6 +10,7 @@ wild wild? non-wild? + ground? variables-in unify unify/env @@ -69,12 +70,24 @@ (define (variables-in x) (let walk ((x x) (acc (set))) (cond - [(variable? x) (set-add acc x)] + [(wild? x) (set-add acc x)] [(pair? x) (walk (car x) (walk (cdr x) acc))] [(vector? x) (foldl walk acc (vector->list x))] [(non-object-struct? x) (walk (struct->vector x #f) acc)] [else acc]))) +;; Any -> Boolean +;; True iff the term is completely ground, that is has no variables or +;; canonical-variables in it. +(define (ground? x) + (let walk ((x x)) + (cond + [(wild? x) #f] + [(pair? x) (and (walk (car x)) (walk (cdr x)))] + [(vector? x) (andmap walk (vector->list x))] + [(non-object-struct? x) (walk (struct->vector x #f))] + [else #t]))) + ;; Variable Any -> Boolean (define (occurs? var val) (let walk ((x val))