From 3ff7aac2d2eb2cbf2f854793fc0d7bc6f1f7d927 Mon Sep 17 00:00:00 2001 From: Rose Hogenson Date: Sun, 9 Jan 2022 08:40:09 -0800 Subject: 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. --- list.csc | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 list.csc (limited to 'list.csc') 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))))))) -- cgit v1.3.1