diff options
Diffstat (limited to 'list.csc')
| -rw-r--r-- | list.csc | 23 |
1 files changed, 22 insertions, 1 deletions
@@ -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)))))))) |
