diff options
| author | Rose Hogenson <rhogenson@posteo.net> | 2022-01-11 22:01:23 -0800 |
|---|---|---|
| committer | Rose Hogenson <rhogenson@posteo.net> | 2022-01-11 22:01:23 -0800 |
| commit | 68986fe0410584c6934c835bb0ee784655f5f8c5 (patch) | |
| tree | d51bc2f3e09df35ef81b7a0c462ff555b4344701 /list.csc | |
| parent | Add a first implementation of a macro expander. (diff) | |
| download | chromatopelma-68986fe0410584c6934c835bb0ee784655f5f8c5.tar.zst | |
Move scheme compiler into a separate directory.
Diffstat (limited to 'list.csc')
| -rw-r--r-- | list.csc | 64 |
1 files changed, 0 insertions, 64 deletions
diff --git a/list.csc b/list.csc deleted file mode 100644 index f425146..0000000 --- a/list.csc +++ /dev/null @@ -1,64 +0,0 @@ -(define-library (csc list) - (export - enumerate - filter - intercalate - revappend - split-at - take) - (import (scheme base) - (only (csc match) - match)) - (begin - - - (define (take n xs) - (let loop ((n n) - (xs xs) - (acc '())) - (if (or (not (positive? n)) (null? xs)) - (reverse acc) - (loop (- n 1) (cdr xs) (cons (car xs) acc))))) - - - (define (split-at n xs) - (let loop ((n n) - (xs xs) - (acc '())) - (if (or (not (positive? n)) (null? xs)) - (values (reverse acc) xs) - (loop (- n 1) (cdr xs) (cons (car xs) acc))))) - - - (define (revappend a b) - (let loop ((xs a) - (acc b)) - (if (null? xs) - acc - (loop (cdr xs) (cons (car xs) acc))))) - - - (define (intercalate x l) - (match l - ('() '()) - ((_) l) - ((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)))))))) |
