2
;;;; Author: Paul Dietz
3
;;;; Created: Sun Nov 10 21:13:04 2002
4
;;;; Contains: Tests for LOOP-AS-HASH forms
8
(defparameter *loop.6.alist*
9
'((a . 1) (b . 2) (c . 3)))
11
(defparameter *loop.6.alist.2*
12
'(("a" . 1) ("b" . 2) ("c" . 3)))
14
(defparameter *loop.6.alist.3*
15
'(((a1 . a2) . 1) ((b1 . b2) . 2) ((c1 . c2) . 3)))
17
(defparameter *loop.6.hash.1*
18
(let ((table (make-hash-table :test #'eq)))
19
(loop for (key . val) in *loop.6.alist*
20
do (setf (gethash key table) val))
23
(defparameter *loop.6.hash.2*
24
(let ((table (make-hash-table :test #'eql)))
25
(loop for (key . val) in *loop.6.alist*
26
do (setf (gethash key table) val))
29
(defparameter *loop.6.hash.3*
30
(let ((table (make-hash-table :test #'equal)))
31
(loop for (key . val) in *loop.6.alist.3*
32
do (setf (gethash key table) val))
35
;;; (defparameter *loop.6.hash.4*
36
;;; (let ((table (make-hash-table :test #'equalp)))
37
;;; (loop for (key . val) in *loop.6.alist.2*
38
;;; do (setf (gethash key table) val))
41
(defparameter *loop.6.hash.5*
42
(let ((table (make-hash-table :test #'eql)))
43
(loop for (val . key) in *loop.6.alist.3*
44
do (setf (gethash key table) val))
47
(defparameter *loop.6.hash.6*
48
(let ((table (make-hash-table :test #'eq)))
49
(loop for (key . val) in *loop.6.alist*
50
do (setf (gethash key table) (coerce val 'float)))
53
(defparameter *loop.6.hash.7*
54
(let ((table (make-hash-table :test #'equal)))
55
(loop for (val . key) in *loop.6.alist.3*
56
do (setf (gethash (coerce key 'float) table) val))
59
(defparameter *loop.6.alist.8*
60
'(((1 . 2) . 1) ((3 . 4) . b) ((5 . 6) . c)))
62
(defparameter *loop.6.hash.8*
63
(let ((table (make-hash-table :test #'equal)))
64
(loop for (key . val) in *loop.6.alist.8*
65
do (setf (gethash key table) val))
68
(defparameter *loop.6.hash.9*
69
(let ((table (make-hash-table :test #'equal)))
70
(loop for (val . key) in *loop.6.alist.8*
71
do (setf (gethash key table) val))
74
;;; being {each | the} {hash-value | hash-values | hash-key | hash-keys} {in | of }
77
(loop for x being the hash-value of *loop.6.hash.1* sum x)
81
(loop for x being the hash-values of *loop.6.hash.1* sum x)
85
(loop for x being each hash-value of *loop.6.hash.1* sum x)
89
(loop for x being each hash-values of *loop.6.hash.1* sum x)
93
(loop for x being the hash-values in *loop.6.hash.1* sum x)
97
(sort (loop for x being the hash-key of *loop.6.hash.1* collect x)
102
(sort (loop for x being the hash-keys of *loop.6.hash.1* collect x)
107
(sort (loop for x being each hash-key of *loop.6.hash.1* collect x)
112
(sort (loop for x being each hash-keys of *loop.6.hash.1* collect x)
117
(sort (loop for x being each hash-keys in *loop.6.hash.1* collect x)
122
(sort (loop for (u . v) being the hash-keys of *loop.6.hash.3* collect u)
127
(sort (loop for (u . v) being the hash-keys of *loop.6.hash.3* collect v)
132
(sort (loop for (u . v) being the hash-values of *loop.6.hash.5* collect u)
137
(sort (loop for (u . v) being the hash-values of *loop.6.hash.5* collect v)
142
(sort (loop for k being the hash-keys of *loop.6.hash.1* using (hash-value v)
148
(sort (loop for v being the hash-values of *loop.6.hash.1* using (hash-key k)
154
(sort (loop for (u . nil) being the hash-values of *loop.6.hash.5* collect u)
159
(sort (loop for (nil . v) being the hash-values of *loop.6.hash.5* collect v)
164
(loop for nil being the hash-values of *loop.6.hash.5* count t)
168
(loop for nil being the hash-keys of *loop.6.hash.5* count t)
172
(loop for v being the hash-values of *loop.6.hash.5* using (hash-key nil) count t)
176
(loop for k being the hash-keys of *loop.6.hash.5* using (hash-value nil) count t)
180
(loop for v fixnum being the hash-values of *loop.6.hash.1* sum v)
184
(loop for v of-type fixnum being the hash-values of *loop.6.hash.1* sum v)
188
(loop for k fixnum being the hash-keys of *loop.6.hash.5* sum k)
192
(loop for k of-type fixnum being the hash-keys of *loop.6.hash.5* sum k)
196
(loop for k t being the hash-keys of *loop.6.hash.5* sum k)
200
(loop for k of-type t being the hash-keys of *loop.6.hash.5* sum k)
204
(loop for v t being the hash-values of *loop.6.hash.1* sum v)
208
(loop for v of-type t being the hash-values of *loop.6.hash.1* sum v)
212
(loop for v float being the hash-values of *loop.6.hash.6* sum v)
216
(loop for v of-type float being the hash-values of *loop.6.hash.6* sum v)
220
(loop for k float being the hash-keys of *loop.6.hash.7* sum k)
224
(loop for k of-type float being the hash-keys of *loop.6.hash.7* sum k)
228
(loop for (k1 . k2) of-type (integer . integer) being the hash-keys
229
of *loop.6.hash.8* sum (+ k1 k2))
233
(loop for (v1 . v2) of-type (integer . integer) being the hash-values
234
of *loop.6.hash.9* sum (+ v1 v2))
238
(loop for v being the hash-values of *loop.6.hash.8*
239
using (hash-key (k1 . k2)) sum (+ k1 k2))
243
(loop for k being the hash-keys of *loop.6.hash.9*
244
using (hash-value (v1 . v2)) sum (+ v1 v2))
248
(loop as x being the hash-value of *loop.6.hash.1* sum x)
252
(sort (loop as x being the hash-key of *loop.6.hash.1* collect x)
258
(deftest loop.6.error.1
260
(loop for k from 1 to 10
261
for k being the hash-keys of *loop.6.hash.1*
266
(deftest loop.6.error.2
268
(loop for k being the hash-keys of *loop.6.hash.1*
274
(deftest loop.6.error.3
276
(loop for (k . k) being the hash-keys of *loop.6.hash.3*
281
(deftest loop.6.error.4
283
(loop for k being the hash-keys of *loop.6.hash.3*
289
(deftest loop.6.error.5
291
(loop for k being the hash-values of *loop.6.hash.3*