loop16.lsp 5.35 KB
Newer Older
1 2 3 4 5
;-*- Mode:     Lisp -*-
;;;; Author:   Paul Dietz
;;;; Created:  Thu Nov 21 09:46:27 2002
;;;; Contains: Tests that uninterned symbols can be loop keywords

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


(deftest loop.16.30
  (loop #:for i #:from 1 #:to 10 #:collect i)
  (1 2 3 4 5 6 7 8 9 10))

(deftest loop.16.31
  (loop #:for i #:upfrom 1 #:below 10 #:by 2 #:collect i)
  (1 3 5 7 9))

(deftest loop.16.32
  (loop #:with x = 1 #:and y = 2 #:return (values x y))
  1 2)

(deftest loop.16.33
  (loop #:named foo #:doing (return-from foo 1))
  1)

(deftest loop.16.34
  (let ((x 0))
    (loop
     #:initially (setq x 2)
     #:until t
     #:finally (return x)))
  2)

(deftest loop.16.35
  (loop #:for x #:in '(a b c) #:collecting x)
  (a b c))

(deftest loop.16.36
  (loop #:for x #:in '(a b c) #:append (list x))
  (a b c))

(deftest loop.16.37
  (loop #:for x #:in '(a b c) #:appending (list x))
  (a b c))

(deftest loop.16.38
  (loop #:for x #:in '(a b c) #:nconc (list x))
  (a b c))

(deftest loop.16.39
  (loop #:for x #:in '(a b c) #:nconcing (list x))
  (a b c))

(deftest loop.16.40
  (loop #:for x #:in '(1 2 3) #:count x)
  3)

(deftest loop.16.41
  (loop #:for x #:in '(1 2 3) #:counting x)
  3)

(deftest loop.16.42
  (loop #:for x #:in '(1 2 3) #:sum x)
  6)

(deftest loop.16.43
  (loop #:for x #:in '(1 2 3) #:summing x)
  6)

(deftest loop.16.44
  (loop #:for x #:in '(10 20 30) #:maximize x)
  30)

(deftest loop.16.45
  (loop #:for x #:in '(10 20 30) #:maximizing x)
  30)

(deftest loop.16.46
  (loop #:for x #:in '(10 20 30) #:minimize x)
  10)

(deftest loop.16.47
  (loop #:for x #:in '(10 20 30) #:minimizing x)
  10)

(deftest loop.16.48
  (loop #:for x #:in '(1 2 3 4) #:sum x #:into foo #:of-type fixnum
sds's avatar
sds committed
87
        #:finally (return foo))
88 89 90 91
  10)

(deftest loop.16.49
  (loop #:for x #:upfrom 1 #:to 10
sds's avatar
sds committed
92 93 94 95
        #:if (evenp x) #:sum x #:into foo
        #:else #:sum x #:into bar
        #:end
        #:finally (return (values foo bar)))
96 97 98 99
  30 25)

(deftest loop.16.50
  (loop #:for x #:downfrom 10 #:above 0
sds's avatar
sds committed
100 101 102 103
        #:when (evenp x) #:sum x #:into foo
        #:else #:sum x #:into bar
        #:end
        #:finally (return (values foo bar)))
104 105 106 107
  30 25)

(deftest loop.16.51
  (loop #:for x #:in '(a b nil c d nil)
sds's avatar
sds committed
108
        #:unless x #:count t)
109 110 111 112
  2)

(deftest loop.16.52
  (loop #:for x #:in '(a b nil c d nil)
sds's avatar
sds committed
113 114 115
        #:unless x #:collect x #:into bar #:and #:count t #:into foo
        #:end
        finally (return (values bar foo)))
116 117 118 119 120
  (nil nil)
  2)

(deftest loop.16.53
  (loop #:for x #:in '(nil nil a b nil c nil)
sds's avatar
sds committed
121 122
        #:collect x
        #:until x)
123 124 125 126
  (nil nil a))

(deftest loop.16.54
  (loop #:for x #:in '(a b nil c nil)
sds's avatar
sds committed
127
        #:while x #:collect x)
128 129 130 131
  (a b))

(deftest loop.16.55
  (loop #:for x #:in '(nil nil a b nil c nil)
sds's avatar
sds committed
132
        #:thereis x)
133 134 135 136
  a)

(deftest loop.16.56
  (loop #:for x #:in '(nil nil a b nil c nil)
sds's avatar
sds committed
137
        #:never x)
138 139 140 141
  nil)

(deftest loop.16.57
  (loop #:for x #:in '(a b c d e)
sds's avatar
sds committed
142
        #:always x)
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
  t)

(deftest loop.16.58
  (loop #:as x #:in '(a b c) #:count t)
  3)

(deftest loop.16.59
  (loop #:for i #:from 10 #:downto 5 #:collect i)
  (10 9 8 7 6 5))

(deftest loop.16.60
  (loop #:for i #:from 0 #:upto 5 #:collect i)
  (0 1 2 3 4 5))

(deftest loop.16.61
  (loop #:for x #:on '(a b c) #:collecting (car x))
  (a b c))

(deftest loop.16.62
  (loop #:for x = '(a b c) #:then (cdr x)
sds's avatar
sds committed
163 164
        #:while x
        #:collect (car x))
165 166 167 168 169 170 171 172
  (a b c))

(deftest loop.16.63
  (loop #:for x #:across #(a b c) #:collect x)
  (a b c))

(deftest loop.16.64
  (loop #:for x #:being #:the #:hash-keys #:of (make-hash-table)
sds's avatar
sds committed
173
        #:count t)
174 175 176 177
  0)

(deftest loop.16.65
  (loop #:for x #:being #:each #:hash-key #:in (make-hash-table)
sds's avatar
sds committed
178
        #:count t)
179 180 181 182
  0)

(deftest loop.16.66
  (loop #:for x #:being #:each #:hash-value #:of (make-hash-table)
sds's avatar
sds committed
183
        #:count t)
184 185 186 187
  0)

(deftest loop.16.67
  (loop #:for x #:being #:the #:hash-values #:in (make-hash-table)
sds's avatar
sds committed
188
        #:count t)
189 190 191 192
  0)

(deftest loop.16.68
  (loop #:for x #:being #:the #:hash-values #:in (make-hash-table)
sds's avatar
sds committed
193 194
        #:using (#:hash-key k)
        #:count t)
195 196 197 198
  0)

(deftest loop.16.69
  (loop #:for x #:being #:the #:hash-keys #:in (make-hash-table)
sds's avatar
sds committed
199 200
        #:using (#:hash-value v)
        #:count t)
201 202 203
  0)

(deftest loop.16.70
204
  (let ()
205 206 207 208 209 210
    (ignore-errors (delete-package "LOOP.16.PACKAGE"))
    (let ((p (make-package "LOOP.16.PACKAGE" :use nil)))
      (loop #:for x #:being #:the #:symbols #:of p #:count t)))
  0)

(deftest loop.16.71
211
  (let ()
212 213 214 215 216 217
    (ignore-errors (delete-package "LOOP.16.PACKAGE"))
    (let ((p (make-package "LOOP.16.PACKAGE" :use nil)))
      (loop #:for x #:being #:each #:symbol #:of p #:count t)))
  0)

(deftest loop.16.72
218
  (let ()
219 220 221 222 223 224
    (ignore-errors (delete-package "LOOP.16.PACKAGE"))
    (let ((p (make-package "LOOP.16.PACKAGE" :use nil)))
      (loop #:for x #:being #:the #:external-symbols #:of p #:count t)))
  0)

(deftest loop.16.73
225
  (let ()
226 227 228 229 230 231
    (ignore-errors (delete-package "LOOP.16.PACKAGE"))
    (let ((p (make-package "LOOP.16.PACKAGE" :use nil)))
      (loop #:for x #:being #:each #:external-symbol #:of p #:count t)))
  0)

(deftest loop.16.74
232
  (let ()
233 234 235 236 237 238
    (ignore-errors (delete-package "LOOP.16.PACKAGE"))
    (let ((p (make-package "LOOP.16.PACKAGE" :use nil)))
      (loop #:for x #:being #:the #:present-symbols #:of p #:count t)))
  0)

(deftest loop.16.75
239
  (let ()
240 241 242 243
    (ignore-errors (delete-package "LOOP.16.PACKAGE"))
    (let ((p (make-package "LOOP.16.PACKAGE" :use nil)))
      (loop #:for x #:being #:each #:present-symbol #:of p #:count t)))
  0)