-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresolver.lisp.orig
42 lines (38 loc) · 1.36 KB
/
resolver.lisp.orig
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
;; Defining some basic types : an atomic sentence, and what it is built of
(defstruct (compound
(:conc-name nil)
(:print-function
(lambda (struct stream depth)
(declare (ignore depth))
(format stream "~A~A"
(compound-op struct)
(compound-args struct)))))
op args)
(defun unify (x y +theta+)
"returns a substitution to make x and y identical"
(print "====UNIFY====")(print x)(print y)(print +theta+)
(cond ((eq +theta+ 'failure) 'failure)
((eql x y) +theta+)
((var? x) (unify-var x y +theta+))
((var? y) (unify-var y x +theta+))
((and (compound-p x) (compound-p y))
(unify (args x) (args y)
(unify (op x) (op y) +theta+)))
((and (listp x) (listp y))
(unify (cdr x) (cdr y)
(unify (car x) (car y) +theta+)))
(t 'failure)))
(defun unify-var (var x +theta+)
"returns a substitution"
<<<<<<< HEAD
(print "====VARR====")(print var)(print x)(print +theta+)
; need some association code here
; we're going to have a data structure : list with two elements
; ( variable value ) that represents {var/val}
=======
>>>>>>> 8fa1edd36cd0c4eb92e875bcd02aa192ccd26712
(cond ((assoc var +theta+) (unify (cadr (assoc var +theta+)) x +theta+))
((assoc x +theta+) (unify var (cadr (assoc x +theta+)) +theta+))
(t (cons (list var x) +theta+))))
(defun var? (a)
(when (symbolp a) (eq (char (string a) 0) #\?)))