-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathposet.lisp
34 lines (27 loc) · 1.05 KB
/
poset.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
(in-package :cl-user)
(defpackage hyperlattices/partially-ordered-set
(:nicknames hyperlattices/poset hl/poset hl-poset partially-ordered-set poset)
(:use c2cl)
(:export #:poset
#:elements
#:leq
#:less-than-p
#:less-than-or-equal-p
#:greater-than-p
#:greater-than-or-equal-p)
(:documentation "Implementation of POSET class for partially-ordered sets."))
(in-package :hyperlattices/partially-ordered-set)
(defclass poset ()
((elements :accessor elements :initarg :elements :type list)
(leq :accessor leq :initarg :leq :type function)))
(defmethod less-than-p ((lhs poset) (rhs poset) x y)
(and (member x (elements lhs))
(member y (elements lhs))
(funcall (leq lhs) x y)))
(defmethod less-than-or-equal-p ((lhs poset) (rhs poset) x y)
(or (equal x y)
(less-than-p lhs rhs x y)))
(defmethod greater-than-p ((lhs poset) (rhs poset) x y)
(less-than-p rhs lhs x y))
(defmethod greater-than-or-equal-p ((lhs poset) (rhs poset) x y)
(less-than-or-equal-p rhs lhs x y))