diff options
Diffstat (limited to 'list.csc')
| -rw-r--r-- | list.csc | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/list.csc b/list.csc new file mode 100644 index 0000000..c4bc013 --- /dev/null +++ b/list.csc @@ -0,0 +1,33 @@ +(define-library (csc list) + (export + revappend + split-at + take) + (import (scheme base)) + (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))))))) |
