Add ground? and fix variables-in
This commit is contained in:
parent
634e795a6c
commit
f1f7cc0d8c
15
unify.rkt
15
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))
|
||||
|
|
Loading…
Reference in New Issue