aboutsummaryrefslogtreecommitdiffstats
path: root/csc/loop-test.csc
diff options
context:
space:
mode:
authorRose Hogenson <rhogenson@posteo.net>2022-07-24 12:52:21 -0700
committerRose Hogenson <rhogenson@posteo.net>2022-07-24 12:52:21 -0700
commitc6b74224fe669bc9d180a409ad13ed269631b316 (patch)
tree3c8caa26be0cd95e62b9c3432ef1a50b9065f0be /csc/loop-test.csc
parentDelete set.csc (diff)
downloadchromatopelma-c6b74224fe669bc9d180a409ad13ed269631b316.tar.zst
Improve the loop macro collect statement.
Now you can use multiple collect statements and they will all accumulate into the same variable. I think in common lisp you could collect into the same variable even with collect x into, but it's pretty unclear to me how to do that in Scheme. How would we know that they are the same variable?
Diffstat (limited to 'csc/loop-test.csc')
-rw-r--r--csc/loop-test.csc30
1 files changed, 30 insertions, 0 deletions
diff --git a/csc/loop-test.csc b/csc/loop-test.csc
index eb9345b..e7341c6 100644
--- a/csc/loop-test.csc
+++ b/csc/loop-test.csc
@@ -20,6 +20,13 @@
collect (+ 1 x))))
+(test loop-collect-nothing
+ (assert-equal
+ '()
+ (loop for x in '()
+ collect x)))
+
+
(test loop-for-arithmetic
(assert-equal
'(1 2 3 4 5)
@@ -207,6 +214,13 @@
maximize x)))
+(test loop-maximize-none
+ (assert-equal
+ 0
+ (loop for x in '()
+ maximize x)))
+
+
(test loop-minimize
(assert-equal
1
@@ -214,6 +228,13 @@
minimize x)))
+(test loop-minimize-none
+ (assert-equal
+ 0
+ (loop for x in '()
+ minimize x)))
+
+
(test loop-if
(assert-equal
5
@@ -251,3 +272,12 @@
5
(loop for x from 0
if (>= x 5) return x end)))
+
+
+(test loop-collect-advanced
+ (assert-equal
+ '(fred bob ken sue alice joe kris sunshine june)
+ (loop for name in '(fred sue alice joe june)
+ for kids in '((bob ken) () () (kris sunshine) ())
+ collect name
+ append kids)))