aboutsummaryrefslogtreecommitdiffstats
path: root/list.csc
diff options
context:
space:
mode:
Diffstat (limited to 'list.csc')
-rw-r--r--list.csc23
1 files changed, 22 insertions, 1 deletions
diff --git a/list.csc b/list.csc
index 799b070..f425146 100644
--- a/list.csc
+++ b/list.csc
@@ -1,5 +1,7 @@
(define-library (csc list)
(export
+ enumerate
+ filter
intercalate
revappend
split-at
@@ -40,4 +42,23 @@
(match l
('() '())
((_) l)
- ((head . tail) (cons head (cons x (intercalate x tail))))))))
+ ((head . tail) (cons head (cons x (intercalate x tail))))))
+
+
+ (define (enumerate l)
+ (let loop ((i 0)
+ (l l))
+ (match l
+ ('() '())
+ ((head . tail) (cons (cons i head) (loop (+ 1 i) tail))))))
+
+
+ (define (filter p l)
+ (let loop ((l l)
+ (acc '()))
+ (match l
+ ('() (reverse acc))
+ ((x . xs)
+ (if (p x)
+ (loop xs (cons x acc))
+ (loop xs acc))))))))