From c6b74224fe669bc9d180a409ad13ed269631b316 Mon Sep 17 00:00:00 2001 From: Rose Hogenson Date: Sun, 24 Jul 2022 12:52:21 -0700 Subject: 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? --- csc/loop-test.csc | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'csc/loop-test.csc') 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))) -- cgit v1.3.1