aboutsummaryrefslogtreecommitdiffstats
path: root/csc/list.csc
diff options
context:
space:
mode:
authorRose Hogenson <rhogenson@posteo.net>2022-01-24 20:40:33 -0800
committerRose Hogenson <rhogenson@posteo.net>2022-01-24 20:40:33 -0800
commitc36d2a16e06e2f3ca9c9c3f8d969411bc8c28f01 (patch)
treed7d0b5206202d5b4471806c96393cc01a46c4a34 /csc/list.csc
parentStore the list length in sort. (diff)
downloadchromatopelma-c36d2a16e06e2f3ca9c9c3f8d969411bc8c28f01.tar.zst
Finish the loop macro.
I also cleaned everything up a lot. Maybe there are still bugs because the test coverage is awful, but for now I'm happy to be done.
Diffstat (limited to 'csc/list.csc')
-rw-r--r--csc/list.csc24
1 files changed, 17 insertions, 7 deletions
diff --git a/csc/list.csc b/csc/list.csc
index dcc1766..95fff04 100644
--- a/csc/list.csc
+++ b/csc/list.csc
@@ -5,7 +5,8 @@
intercalate
revappend
split-at
- take)
+ take
+ unzip)
(import (scheme base)
(only (csc loop)
loop
@@ -22,11 +23,13 @@
(define (split-at n xs)
- (loop for i from 1 to n
- for x in xs
- collect x into first-half
- for second-half = xs then (cdr second-half)
- finally (return (values first-half second-half))))
+ (if (<= n 0)
+ (values '() xs)
+ (loop for i from 1 to n
+ for x in xs
+ for second-half = (cdr xs) then (cdr second-half)
+ collect x into first-half
+ finally (return (values first-half second-half)))))
(define (revappend a b)
@@ -60,4 +63,11 @@
((x . xs)
(if (p x)
(loop xs (cons x acc))
- (loop xs acc))))))))
+ (loop xs acc))))))
+
+
+ (define (unzip l)
+ (loop for x in l
+ collect (car x) into xs
+ collect (cdr x) into ys
+ finally (return (values xs ys))))))