2
;;;; Author: Paul Dietz
3
;;;; Created: Sat May 24 21:31:55 2003
4
;;;; Contains: Tests of DEFGENERIC with :method-combination AND
8
(declaim (special *x*))
10
(compile-and-load "defgeneric-method-combination-aux.lsp")
12
(deftest defgeneric-method-combination.and.1
15
(eval '(defgeneric dg-mc.fun.and.1 (x)
16
(:method-combination and)
17
(:method and ((x integer)) (push 4 *x*) t)
18
(:method and ((x rational)) (push 3 *x*) nil)
19
(:method and ((x number)) (push 2 *x*) t)
20
(:method and ((x t)) (push 1 *x*) 'a)))))
21
(declare (type generic-function fn))
24
(list (funcall fn y) *x*))))
25
(values (%f 1) (%f 2/3) (%f 1.54) (%f 'a))))
31
(deftest defgeneric-method-combination.and.2
34
(eval '(defgeneric dg-mc.fun.and.2 (x)
35
(:method-combination and :most-specific-first)
36
(:method and ((x integer)) (push 4 *x*) t)
37
(:method and ((x rational)) (push 3 *x*) nil)
38
(:method and ((x number)) (push 2 *x*) t)
39
(:method and ((x t)) (push 1 *x*) 'a)))))
40
(declare (type generic-function fn))
43
(list (funcall fn y) *x*))))
44
(values (%f 1) (%f 2/3) (%f 1.54) (%f 'a))))
50
(deftest defgeneric-method-combination.and.3
53
(eval '(defgeneric dg-mc.fun.and.3 (x)
54
(:method-combination and :most-specific-last)
55
(:method and ((x integer)) (push 4 *x*) t)
56
(:method and ((x rational)) (push 3 *x*) nil)
57
(:method and ((x number)) (push 2 *x*) 'a)
58
(:method and ((x t)) (push 1 *x*) t)))))
59
(declare (type generic-function fn))
62
(list (funcall fn y) *x*))))
63
(values (%f 1) (%f 2/3) (%f 1.54) (%f 'a))))
69
(deftest defgeneric-method-combination.and.4
71
(eval '(defgeneric dg-mc.and.4 (x)
72
(:method-combination and)
73
(:method and ((x integer)) t)
74
(:method :around ((x rational)) 'foo)
75
(:method and ((x number)) nil)
76
(:method and ((x symbol)) t)
77
(:method and ((x t)) 'a)))))
78
(declare (type generic-function fn))
84
(funcall fn '(a b c))))
87
(deftest defgeneric-method-combination.and.5
89
(eval '(defgeneric dg-mc.and.5 (x)
90
(:method-combination and)
91
(:method and ((x integer)) nil)
92
(:method :around ((x rational))
93
(list 'foo (call-next-method)))
94
(:method and ((x number)) 'a)
95
(:method and ((x symbol)) 'b)
96
(:method and ((x t)) 'c)))))
97
(declare (type generic-function fn))
103
(funcall fn '(a b c))))
104
(foo nil) (foo c) c c c)
106
(deftest defgeneric-method-combination.and.6
108
(eval '(defgeneric dg-mc.and.6 (x)
109
(:method-combination and)
110
(:method and ((x integer)) 'a)
111
(:method :around ((x rational))
112
(list 'foo (call-next-method)))
113
(:method :around ((x real))
114
(list 'bar (call-next-method)))
115
(:method and ((x number)) nil)
116
(:method and ((x symbol)) 'c)
117
(:method and ((x t)) 'd)))))
118
(declare (type generic-function fn))
123
(funcall fn #c(1.0 2.0))
125
(funcall fn '(a b c))))
126
(foo (bar nil)) (foo (bar nil)) (bar nil) nil d d)
128
(deftest defgeneric-method-combination.and.7
130
(eval '(defgeneric dg-mc.and.7 (x)
131
(:method-combination and)
132
(:method and ((x dgmc-class-04)) 'c)
133
(:method and ((x dgmc-class-03)) 'b)
134
(:method and ((x dgmc-class-02)) nil)
135
(:method and ((x dgmc-class-01)) 'a)))))
136
(declare (type generic-function fn))
138
(funcall fn (make-instance 'dgmc-class-01))
139
(funcall fn (make-instance 'dgmc-class-02))
140
(funcall fn (make-instance 'dgmc-class-03))
141
(funcall fn (make-instance 'dgmc-class-04))))
144
(deftest defgeneric-method-combination.and.8
146
(eval '(defgeneric dg-mc.and.8 (x)
147
(:method-combination and)
148
(:method and ((x (eql 1000))) 'a)
149
(:method :around ((x symbol)) (values))
150
(:method :around ((x integer)) (values 'a 'b 'c))
151
(:method :around ((x complex)) (call-next-method))
152
(:method :around ((x number)) (values 1 2 3 4 5 6))
153
(:method and ((x t)) 'b)))))
154
(declare (type generic-function fn))
156
(multiple-value-list (funcall fn 'a))
157
(multiple-value-list (funcall fn 10))
158
(multiple-value-list (funcall fn #c(9 8)))
159
(multiple-value-list (funcall fn '(a b c)))))
160
() (a b c) (1 2 3 4 5 6) (b))
162
(deftest defgeneric-method-combination.and.9
164
(let ((fn (eval '(defgeneric dg-mc.and.9 (x)
165
(:method-combination and)))))
166
(declare (type generic-function fn))
171
(deftest defgeneric-method-combination.and.10
173
(eval '(defgeneric dg-mc.and.10 (x)
174
(:method-combination and)
175
(:method ((x t)) t)))
181
(deftest defgeneric-method-combination.and.11
183
(eval '(defgeneric dg-mc.and.11 (x)
184
(:method-combination and)
185
(:method nonsense ((x t)) t)))
191
(deftest defgeneric-method-combination.and.12
192
(let ((fn (eval '(defgeneric dg-mc.and.12 (x)
193
(:method-combination and)
194
(:method :around ((x t)) t)
195
(:method and ((x integer)) x)))))
196
(declare (type generic-function fn))
197
(handler-case (funcall fn 'x)