From 77583a881b03ce38c8065c40641489fe88b61eb2 Mon Sep 17 00:00:00 2001 From: Rose Hogenson Date: Sun, 9 Jan 2022 22:55:59 -0800 Subject: Write the linker. --- list.csc | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'list.csc') 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)))))))) -- cgit v1.3.1