2
;;;; Author: Paul Dietz
3
;;;; Created: Sat May 17 18:04:10 2003
4
;;;; Contains: Tests of WITH-SLOTS
13
(with-slots () nil (values)))
16
(with-slots () nil (values 'a 'b 'c 'd 'e 'f))
20
(let ((x 0) (y 10) (z 20))
23
(with-slots () (incf x) (incf y 3) (incf z 100))
29
;;; with-slots is an implicit progn, not a tagbody
37
(return-from done :bad))
39
(return-from done :good)))
42
;;; with-slots has no implicit block
45
(with-slots () nil (return :good))
50
;;; Tests on standard objects
52
(defclass with-slots-class-01 () ((a :initarg :a)
57
(let ((obj (make-instance 'with-slots-class-01 :a 'x :b 'y :c 'z)))
58
(with-slots (a b c) obj (values a b c)))
62
(let ((obj (make-instance 'with-slots-class-01 :a 'x :b 'y :c 'z)))
65
(values (setf a 'p) (setf b 'q) (setf c 'r)
66
(map-slot-value obj '(a b c)))))
70
(let ((obj (make-instance 'with-slots-class-01 :a 'x :b 'y :c 'z)))
73
(values (setq a 'p) (setq b 'q) (setq c 'r)
74
(map-slot-value obj '(a b c)))))
77
(deftest with-slots.10
78
(let ((obj (make-instance 'with-slots-class-01 :a 'x :b 'y :c 'z)))
79
(with-slots ((a2 a) (b2 b) (c2 c)) obj (values a2 b2 c2)))
82
(deftest with-slots.11
83
(let ((obj (make-instance 'with-slots-class-01 :a 'x :b 'y :c 'z)))
85
((a2 a) (b2 b) (c2 c)) obj
86
(values (setf a2 'p) (setf b2 'q) (setf c2 'r)
87
(map-slot-value obj '(a b c)))))
90
(deftest with-slots.12
91
(let ((obj (make-instance 'with-slots-class-01 :a 'x :b 'y :c 'z)))
93
((a2 a) (b2 b) (c2 c)) obj
94
(values (setq a2 'p) (setq b2 'q) (setq c2 'r)
95
(map-slot-value obj '(a b c)))))
98
(deftest with-slots.13
99
(let ((obj (make-instance 'with-slots-class-01)))
102
(values (setf a 'p) (setf b 'q) (setf c 'r)
103
(map-slot-value obj '(a b c)))))
106
(deftest with-slots.14
107
(let ((obj (make-instance 'with-slots-class-01 :a 1 :b 2 :c 3)))
108
(with-slots (a b c) obj
109
(let ((obj (make-instance 'with-slots-class-01
110
:a 'bad :b 'bad :c 'bad)))
115
(deftest with-slots.15
116
(let ((obj (make-instance 'with-slots-class-01 :a 1 :b 2 :c 3)))
117
(with-slots (a b c) obj
119
((a2 a) (b2 b) (c2 c))
120
(make-instance 'with-slots-class-01
121
:a 'bad :b 'bad :c 'bad)
125
(deftest with-slots.16
126
(let ((obj (make-instance 'with-slots-class-01 :a 'bad :b 'bad :c 'bad)))
127
(with-slots (a b c) obj
130
(make-instance 'with-slots-class-01 :a 1 :b 2 :c 3)
135
(deftest with-slots.17
136
(let ((obj (make-instance 'with-slots-class-01 :a 1 :b 2 :c 'bad)))
137
(with-slots (a b) obj
140
(make-instance 'with-slots-class-01 :a 'bad :b 'bad :c 3)
144
;;; If slot is unbound, act as if slot-value had been called
146
(defmethod slot-unbound ((class t)
147
(instance with-slots-class-01)
151
(deftest with-slots.18
152
(let ((obj (make-instance 'with-slots-class-01)))
153
(with-slots (a b c) obj (values a b c)))
154
missing missing missing)
156
(deftest with-slots.19
157
(let ((obj (make-instance 'with-slots-class-01 :a 'x :b 'y :c 'z)))
158
(with-slots (a b c) obj
159
(declare (optimize (speed 3) (safety 3)))
163
(deftest with-slots.20
164
(let ((obj (make-instance 'with-slots-class-01 :a 'x :b 'y :c 'z)))
165
(with-slots (a b c) obj
166
(declare (optimize (speed 3) (safety 3)))
167
(declare (special *x*))