From f1f7cc0d8c5d9c67d947aec3836b67ced12d7ffe Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Fri, 11 May 2012 14:57:50 -0400 Subject: [PATCH] Add ground? and fix variables-in --- unify.rkt | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) 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))