-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfol.lisp
70 lines (66 loc) · 2.22 KB
/
fol.lisp
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
(defpackage #:fol
(:documentation "Datatypes for first order logic and schemas")
(:use :common-lisp)
(:export fol-predicate
fol-variable
fol-function
name
args
fol-eq))
(in-package :fol)
(defgeneric fol-eq (a b)
(:documentation "Equality as specified for first order logic formulas."))
(defmethod fol-eq ((a t) (b t))
nil)
(defclass fol-variable (common-lisp:standard-object)
((name
:initarg :name
:initform ""
:type string
:documentation "The name of the variable as a string")))
(defmethod fol-eq ((a fol-variable) (b fol-variable))
(equal (slot-value a 'name) (slot-value b 'name)))
(defmethod print-object ((object fol-variable) out)
(format out "V.~a" (slot-value object 'name)))
(defclass fol-function (standard-object)
((name
:initarg :name
:initform ""
:type string
:documentation "The name of the function as a string")
(args
:initarg :args
:initform '()
:type list
:documentation "The arguments to the function as a list of fol-value")))
(defmethod fol-eq ((a fol-function) (b fol-function))
(and
(equal (slot-value a 'name) (slot-value b 'name))
(reduce (lambda (x y) (and x y)) (mapcar #'fol-eq
(slot-value a 'args)
(slot-value b 'args))
:initial-value t)))
(defmethod print-object ((object fol-function) out)
(with-slots (name args) object
(format out "F.~a(~{~a~^,~})" name args)))
(defclass fol-predicate (standard-object)
((name
:initarg :name
:initform ""
:type string
:documentation "The name of the predicate as a string")
(args
:initarg :args
:initform '()
:type list
:documentation "The arguments to the predicate as a list of fol-value")))
(defmethod fol-eq ((a fol-predicate) (b fol-predicate))
(and
(equal (slot-value a 'name) (slot-value b 'name))
(reduce (lambda (x y) (and x y)) (mapcar #'fol-eq
(slot-value a 'args)
(slot-value b 'args))
:initial-value t)))
(defmethod print-object ((object fol-predicate) out)
(with-slots (name args) object
(format out "P.~a(~{~a~^,~})" name args)))