2
;;;; Author: Paul Dietz
3
;;;; Created: Sat May 24 21:31:55 2003
4
;;;; Contains: Tests of DEFGENERIC with :method-combination MAX
8
(declaim (special *x*))
10
(compile-and-load "defgeneric-method-combination-aux.lsp")
12
(deftest defgeneric-method-combination.max.1
15
(eval '(defgeneric dg-mc.fun.max.1 (x)
16
(:method-combination max)
17
(:method max ((x integer)) (car (push 8 *x*)))
18
(:method max ((x rational)) (car (push 4 *x*)))
19
(:method max ((x number)) (car (push 2 *x*)))
20
(:method max ((x t)) (car (push 1 *x*)))))))
21
(declare (type generic-function fn))
24
(list (funcall fn y) *x*))))
25
(values (%f 1) (%f 2/3) (%f 1.54) (%f 'a))))
26
(8 (1 2 4 8)) (4 (1 2 4)) (2 (1 2)) (1 (1)))
28
(deftest defgeneric-method-combination.max.2
31
(eval '(defgeneric dg-mc.fun.max.2 (x)
32
(:method-combination max :most-specific-first)
33
(:method max ((x integer)) (car (push 8 *x*)))
34
(:method max ((x rational)) (car (push 4 *x*)))
35
(:method max ((x number)) (car (push 2 *x*)))
36
(:method max ((x t)) (car (push 1 *x*)))))))
37
(declare (type generic-function fn))
40
(list (funcall fn y) *x*))))
41
(values (%f 1) (%f 2/3) (%f 1.54) (%f 'a))))
42
(8 (1 2 4 8)) (4 (1 2 4)) (2 (1 2)) (1 (1)))
44
(deftest defgeneric-method-combination.max.3
47
(eval '(defgeneric dg-mc.fun.max.3 (x)
48
(:method-combination max :most-specific-last)
49
(:method max ((x integer)) (car (push 8 *x*)))
50
(:method max ((x rational)) (car (push 4 *x*)))
51
(:method max ((x number)) (car (push 2 *x*)))
52
(:method max ((x t)) (car (push 1 *x*)))))))
53
(declare (type generic-function fn))
56
(list (funcall fn y) *x*))))
57
(values (%f 1) (%f 2/3) (%f 1.54) (%f 'a))))
58
(8 (8 4 2 1)) (4 (4 2 1)) (2 (2 1)) (1 (1)))
60
(deftest defgeneric-method-combination.max.4
62
(eval '(defgeneric dg-mc.max.4 (x)
63
(:method-combination max)
64
(:method max ((x integer)) 4)
65
(:method :around ((x rational)) 'foo)
66
(:method max ((x number)) 3)
67
(:method max ((x symbol)) 5)
68
(:method max ((x t)) 1)))))
69
(declare (type generic-function fn))
75
(funcall fn '(a b c))))
78
(deftest defgeneric-method-combination.max.5
80
(eval '(defgeneric dg-mc.max.5 (x)
81
(:method-combination max)
82
(:method max ((x integer)) 5)
83
(:method :around ((x rational))
84
(list 'foo (call-next-method)))
85
(:method max ((x number)) 5/2)
86
(:method max ((x symbol)) 4)
87
(:method max ((x t)) 1.0)))))
88
(declare (type generic-function fn))
94
(funcall fn '(a b c))))
95
(foo 5) (foo 5/2) 5/2 4 1.0)
97
(deftest defgeneric-method-combination.max.6
99
(eval '(defgeneric dg-mc.max.6 (x)
100
(:method-combination max)
101
(:method max ((x integer)) 9)
102
(:method :around ((x rational))
103
(list 'foo (call-next-method)))
104
(:method :around ((x real))
105
(list 'bar (call-next-method)))
106
(:method max ((x number)) 4)
107
(:method max ((x symbol)) 6)
108
(:method max ((x t)) 1)))))
109
(declare (type generic-function fn))
114
(funcall fn #c(1.0 2.0))
116
(funcall fn '(a b c))))
117
(foo (bar 9)) (foo (bar 4)) (bar 4) 4 6 1)
119
(deftest defgeneric-method-combination.max.7
121
(eval '(defgeneric dg-mc.max.7 (x)
122
(:method-combination max)
123
(:method max ((x dgmc-class-04)) 4)
124
(:method max ((x dgmc-class-03)) 3)
125
(:method max ((x dgmc-class-02)) 5)
126
(:method max ((x dgmc-class-01)) 1)))))
127
(declare (type generic-function fn))
129
(funcall fn (make-instance 'dgmc-class-01))
130
(funcall fn (make-instance 'dgmc-class-02))
131
(funcall fn (make-instance 'dgmc-class-03))
132
(funcall fn (make-instance 'dgmc-class-04))))
135
(deftest defgeneric-method-combination.max.8
137
(eval '(defgeneric dg-mc.max.8 (x)
138
(:method-combination max)
139
(:method max ((x (eql 1000))) 4)
140
(:method :around ((x symbol)) (values))
141
(:method :around ((x integer)) (values 'a 'b 'c))
142
(:method :around ((x complex)) (call-next-method))
143
(:method :around ((x number)) (values 1 2 3 4 5 6))
144
(:method max ((x t)) 1)))))
145
(declare (type generic-function fn))
147
(multiple-value-list (funcall fn 'a))
148
(multiple-value-list (funcall fn 10))
149
(multiple-value-list (funcall fn #c(9 8)))
150
(multiple-value-list (funcall fn '(a b c)))))
151
() (a b c) (1 2 3 4 5 6) (1))
153
(deftest defgeneric-method-combination.max.9
155
(let ((fn (eval '(defgeneric dg-mc.max.9 (x)
156
(:method-combination max)))))
157
(declare (type generic-function fn))
158
(funcall fn (list 'a)))
162
(deftest defgeneric-method-combination.max.10
164
(eval '(defgeneric dg-mc.max.10 (x)
165
(:method-combination max)
166
(:method ((x t)) 0)))
172
(deftest defgeneric-method-combination.max.11
174
(eval '(defgeneric dg-mc.max.11 (x)
175
(:method-combination max)
176
(:method nonsense ((x t)) 0)))
182
(deftest defgeneric-method-combination.max.12
183
(let ((fn (eval '(defgeneric dg-mc.max.12 (x)
184
(:method-combination max)
185
(:method :around ((x t)) 1)
186
(:method max ((x integer)) x)))))
187
(declare (type generic-function fn))
188
(handler-case (funcall fn 'a)