-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathord.lisp
More file actions
142 lines (113 loc) · 3.64 KB
/
ord.lisp
File metadata and controls
142 lines (113 loc) · 3.64 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
;; ord.lisp
;; --------------------------------------------------------------------------------------
;; Compare ordering of various types
;;
;; Copyright (C) 2008 by SpectroDynamics, LLC. All rights reserved.
;;
;; DM/SD 08/08
;; --------------------------------------------------------------------------------------
;; ------------------------------------------------------------------------
(in-package :ord)
;; ------------------------------------------------------------------------
(defmethod compare ((a real) (b real))
#f
(- a b))
(defmethod compare ((a character) (b character))
#f
(cond ((char= a b) 0)
((char< a b) -1)
(t 1)))
(defmethod compare ((a string) (b string))
#f
(cond ((string= a b) 0)
((string< a b) -1)
(t 1)))
(defmethod compare ((a symbol) (b symbol))
#f
(compare (symbol-name a) (symbol-name b)))
(defmethod compare ((a pathname) (b pathname))
#f
(compare (namestring a) (namestring b)))
(defstruct ci-char
c)
(defmethod compare ((a ci-char) (b ci-char))
#f
(let ((ca (ci-char-c a))
(cb (ci-char-c b)))
(cond ((char-equal ca cb) 0)
((char-lessp ca cb) -1)
(t 1))))
(defstruct ci-string
s)
(defmethod compare ((a ci-string) (b ci-string))
#f
(let ((sa (ci-string-s a))
(sb (ci-string-s b)))
(cond ((string-equal sa sb) 0)
((string-lessp sa sb) -1)
(t 1))))
;; ------------------------------------------
(defun compare< (a b)
#f
(minusp (the fixnum (compare a b))))
(defun compare<= (a b)
#f
(not (plusp (the fixnum (compare a b)))))
(defun compare= (a b)
#f
(zerop (the fixnum (compare a b))))
(defun compare>= (a b)
#f
(not (minusp (the fixnum (compare a b)))))
(defun compare> (a b)
#f
(plusp (the fixnum (compare a b))))
;; ------------------------------------------------------------------------
#|
(defmethod compare= (a b)
(eql a b))
(defmethod compare= ((a number) (b number))
(= a b))
(defmethod compare= ((a string) (b string))
(string= a b))
(defstruct string-ci
str)
(defmethod compare= ((a string-ci) (b string-ci))
(string-equal (string-ci-str a) (string-ci-str b)))
(defmethod compare= ((a character) (b character))
(char= a b))
(defstruct char-ci
char)
(defmethod compare= ((a char-ci) (b char-ci))
(char-equal (char-ci-char a) (char-ci-char b)))
(defmethod compare= ((a pathname) (b pathname))
(pathname-match-p a b))
(defmethod compare= ((a list) (b list))
(cond ((null a) (null b))
((null b) nil)
(t (and (compare= (first a) (first b))
(compare= (rest a) (rest b))))
))
(defmethod compare= ((a array) (b array))
(and (= (array-rank a) (array-rank b))
(every '= (array-dimensions a) (array-dimensions b))
(eql (adjustable-array-p a) (adjustable-array-p b))
(eql (array-element-type a) (array-element-type b))
(every 'compare=
(make-array (array-total-size a)
:element-type (array-element-type a)
:displaced-to a
:displaced-index-offset 0)
(make-array (array-total-size b)
:element-type (array-element-type b)
:displaced-to b
:displaced-index-offset 0))
))
(defmethod compare= ((a vector) (b vector))
(and (= (length a) (length b))
(eql (array-element-type a) (array-element-type b))
(eql (adjustable-array-p a) (adjustable-array-p b))
(eql (fill-pointer a) (fill-pointer b))
(every 'compare= a b)))
|#
;; ------------------------------------------------------------------------