0.8.3.51:
[sbcl.git] / tests / loop.pure.lisp
index 7e6d4ce..95933d4 100644 (file)
     (ignore-errors
       (loop for i in '(1 2 3) thereis (= i 3) collect i))
   (assert (null result))
-  (assert (typep error 'program-error)))
\ No newline at end of file
+  (assert (typep error 'program-error)))
+
+(multiple-value-bind (result error)
+    (ignore-errors
+      (loop with i = 1 for x from 1 to 3 collect x into i))
+  (assert (null result))
+  (assert (typep error 'program-error)))
+(multiple-value-bind (result error)
+    ;; this one has a plausible interpretation in terms of LET*, but
+    ;; ANSI seems specifically to disallow it
+    (ignore-errors
+      (loop with i = 1 with i = (1+ i)
+           for x from 1 to 3
+           collect (+ x i)))
+  (assert (null result))
+  (assert (typep error 'program-error)))
+
+(let ((it 'z))
+  (assert (equal
+          ;; this one just seems weird.  Nevertheless...
+          (loop for i in '(a b c d)
+                when i
+                  collect it
+                  and collect it)
+          '(a z b z c z d z))))
+
+(let ((ht (make-hash-table)))
+  (setf (gethash 1 ht) 3)
+  (setf (gethash 7 ht) 15)
+  (assert (= (loop for v fixnum being each hash-key in ht sum v) 8))
+  (assert (= (loop for v fixnum being each hash-value in ht sum v) 18))
+  (assert (raises-error? (loop for v float being each hash-value in ht sum v)
+                         type-error)))