diff --git a/ansi-tests/ansi-aux.lsp b/ansi-tests/ansi-aux.lsp index a10f13fbc839e8201f34fd13a33927b429fed6a6..b960417cad6e54e2ce01a5bb41d3bbdcf121edc9 100644 --- a/ansi-tests/ansi-aux.lsp +++ b/ansi-tests/ansi-aux.lsp @@ -217,6 +217,8 @@ the condition to go uncaught if it cannot be classified." (defun string-invertcase (s) (map 'string #'char-invertcase s)) +(defun symbol< (x &rest args) + (apply #'string< (symbol-name x) (mapcar #'symbol-name args))) (defun random-from-seq (seq) "Generate a random member of a sequence." diff --git a/ansi-tests/gclload2.lsp b/ansi-tests/gclload2.lsp index ce4a33f253d0736c848df9690f22bfc35004f106..fc71d13d773221d164b125fbc14fc57fcfae7703 100644 --- a/ansi-tests/gclload2.lsp +++ b/ansi-tests/gclload2.lsp @@ -79,6 +79,7 @@ (load "loop3.lsp") (load "loop4.lsp") (load "loop5.lsp") +(load "loop6.lsp") ;;; Tests of conses diff --git a/ansi-tests/loop5.lsp b/ansi-tests/loop5.lsp index 5c2f4e052915973be1848e376c910fbe080c91df..e613502c971fc5829d8c07372d1832a8bb3f6d01 100644 --- a/ansi-tests/loop5.lsp +++ b/ansi-tests/loop5.lsp @@ -101,8 +101,20 @@ (loop for e across y collect e)) (b c d)) +;;; tests of 'as' form +(deftest loop.5.33 + (loop as e across "abc" collect e) + (#\a #\b #\c)) + +(deftest loop.5.34 + (loop as e of-type character across "abc" collect e) + (#\a #\b #\c)) +(deftest loop.5.35 + (loop as e of-type integer across (the simple-vector (coerce '(1 2 3) 'simple-vector)) + sum e) + 6) ;;; Error cases diff --git a/ansi-tests/loop6.lsp b/ansi-tests/loop6.lsp new file mode 100644 index 0000000000000000000000000000000000000000..5960cbaa2737870a3173cdb494ce34897be6ba2e --- /dev/null +++ b/ansi-tests/loop6.lsp @@ -0,0 +1,134 @@ +;-*- Mode: Lisp -*- +;;;; Author: Paul Dietz +;;;; Created: Sun Nov 10 21:13:04 2002 +;;;; Contains: Tests for LOOP-AS-HASH forms + +(in-package :cl-test) + +(defparameter *loop.6.alist* + '((a . 1) (b . 2) (c . 3))) + +(defparameter *loop.6.alist.2* + '(("a" . 1) ("b" . 2) ("c" . 3))) + +(defparameter *loop.6.alist.3* + '(((a1 . a2) . 1) ((b1 . b2) . 2) ((c1 . c2) . 3))) + +(defparameter *loop.6.hash.1* + (let ((table (make-hash-table :test #'eq))) + (loop for (key . val) in *loop.6.alist* + do (setf (gethash key table) val)) + table)) + +(defparameter *loop.6.hash.2* + (let ((table (make-hash-table :test #'eql))) + (loop for (key . val) in *loop.6.alist* + do (setf (gethash key table) val)) + table)) + +(defparameter *loop.6.hash.3* + (let ((table (make-hash-table :test #'equal))) + (loop for (key . val) in *loop.6.alist.3* + do (setf (gethash key table) val)) + table)) + +;;; (defparameter *loop.6.hash.4* +;;; (let ((table (make-hash-table :test #'equalp))) +;;; (loop for (key . val) in *loop.6.alist.2* +;;; do (setf (gethash key table) val)) +;;; table)) + +(defparameter *loop.6.hash.5* + (let ((table (make-hash-table :test #'eql))) + (loop for (val . key) in *loop.6.alist.3* + do (setf (gethash key table) val)) + table)) + +;;; being {each | the} {hash-value | hash-values | hash-key | hash-keys} {in | of } + +(deftest loop.6.1 + (loop for x being the hash-value of *loop.6.hash.1* sum x) + 6) + +(deftest loop.6.2 + (loop for x being the hash-values of *loop.6.hash.1* sum x) + 6) + +(deftest loop.6.3 + (loop for x being each hash-value of *loop.6.hash.1* sum x) + 6) + +(deftest loop.6.4 + (loop for x being each hash-values of *loop.6.hash.1* sum x) + 6) + +(deftest loop.6.5 + (loop for x being the hash-values in *loop.6.hash.1* sum x) + 6) + +(deftest loop.6.6 + (sort (loop for x being the hash-key of *loop.6.hash.1* collect x) + #'symbol<) + (a b c)) + +(deftest loop.6.7 + (sort (loop for x being the hash-keys of *loop.6.hash.1* collect x) + #'symbol<) + (a b c)) + +(deftest loop.6.8 + (sort (loop for x being each hash-key of *loop.6.hash.1* collect x) + #'symbol<) + (a b c)) + +(deftest loop.6.9 + (sort (loop for x being each hash-keys of *loop.6.hash.1* collect x) + #'symbol<) + (a b c)) + +(deftest loop.6.10 + (sort (loop for x being each hash-keys in *loop.6.hash.1* collect x) + #'symbol<) + (a b c)) + +(deftest loop.6.11 + (sort (loop for (u . v) being the hash-keys of *loop.6.hash.3* collect u) + #'symbol<) + (a1 b1 c1)) + +(deftest loop.6.12 + (sort (loop for (u . v) being the hash-keys of *loop.6.hash.3* collect v) + #'symbol<) + (a2 b2 c2)) + +(deftest loop.6.13 + (sort (loop for (u . v) being the hash-values of *loop.6.hash.5* collect u) + #'symbol<) + (a1 b1 c1)) + +(deftest loop.6.14 + (sort (loop for (u . v) being the hash-values of *loop.6.hash.5* collect v) + #'symbol<) + (a2 b2 c2)) + +(deftest loop.6.15 + (sort (loop for k being the hash-keys of *loop.6.hash.1* using (hash-value v) + collect (list k v)) + #'< :key #'second) + ((a 1) (b 2) (c 3))) + +(deftest loop.6.16 + (sort (loop for v being the hash-values of *loop.6.hash.1* using (hash-key k) + collect (list k v)) + #'< :key #'second) + ((a 1) (b 2) (c 3))) + +(deftest loop.6.17 + (sort (loop for (u . nil) being the hash-values of *loop.6.hash.5* collect u) + #'symbol<) + (a1 b1 c1)) + +(deftest loop.6.18 + (sort (loop for (nil . v) being the hash-values of *loop.6.hash.5* collect v) + #'symbol<) + (a2 b2 c2))