diff options
| author | Rose Hogenson <rhogenson@posteo.net> | 2022-01-09 08:40:09 -0800 |
|---|---|---|
| committer | Rose Hogenson <rhogenson@posteo.net> | 2022-01-09 08:40:09 -0800 |
| commit | 3ff7aac2d2eb2cbf2f854793fc0d7bc6f1f7d927 (patch) | |
| tree | cef8ca0e77c40a70daaca40af25572437d563105 /list.csc | |
| download | chromatopelma-3ff7aac2d2eb2cbf2f854793fc0d7bc6f1f7d927.tar.zst | |
Initial commit.
Not sure if everything here will be needed eventually, but we have a
working bytecode interpreter. Next I will write the linker, then the
core compiler, and finish with the macro expander.
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))))))) |
