diff options
-rw-r--r-- | module/hnh/util.scm | 3 | ||||
-rw-r--r-- | tests/test/util.scm | 10 |
2 files changed, 13 insertions, 0 deletions
diff --git a/module/hnh/util.scm b/module/hnh/util.scm index ffac17bd..36b56c58 100644 --- a/module/hnh/util.scm +++ b/module/hnh/util.scm @@ -118,6 +118,9 @@ ((for (<var> <vars> ...) in <collection> b1 body ...) (map ((@ (ice-9 match) match-lambda) [(<var> <vars> ...) b1 body ...]) <collection>)) + ((for (<var> <vars> ... . <tail>) in <collection> b1 body ...) + (map ((@ (ice-9 match) match-lambda) [(<var> <vars> ... . <tail>) b1 body ...]) + <collection>)) ((for <var> in <collection> b1 body ...) (map (lambda (<var>) b1 body ...) <collection>)))) diff --git a/tests/test/util.scm b/tests/test/util.scm index c91017fc..2a171d12 100644 --- a/tests/test/util.scm +++ b/tests/test/util.scm @@ -49,6 +49,16 @@ (for (x c) in (zip (iota 12) (string->list "Hello, World")) x)) +(test-equal "for with improper list elements" + `(3 7) + (for (a . b) in '((1 . 2) (3 . 4)) + (+ a b))) + +(test-equal "for with longer improper list elements" + '(1 2 4) + (for (a b . c) in '((1 -1 . 1) (2 -2 . 2) (4 -4 . 4)) + (* c (+ 1 a b)))) + (test-equal "procedure label" 120 ((label factorial (lambda (n) |