diff options
| author | Rose Hogenson <rhogenson@posteo.net> | 2023-05-01 07:56:42 -0700 |
|---|---|---|
| committer | Rose Hogenson <rhogenson@posteo.net> | 2023-05-01 07:56:42 -0700 |
| commit | a89d6c82e981fec7d6e4c975e083d2b9e04467ad (patch) | |
| tree | d5445ceb797473dd45ac006c337d990e5dd6f0d4 /lib/csc/list.csc | |
| parent | Fix bugs with recursive macros and empty template. (diff) | |
| download | chromatopelma-a89d6c82e981fec7d6e4c975e083d2b9e04467ad.tar.zst | |
Rewrite most of the compiler.
This represents a major step back in terms of functionality, and amount
of code. The latter I think constitutes a major win. Next steps are to
reimplement syntax-rules, call/cc, and call-with-values.
Diffstat (limited to 'lib/csc/list.csc')
| -rw-r--r-- | lib/csc/list.csc | 85 |
1 files changed, 0 insertions, 85 deletions
diff --git a/lib/csc/list.csc b/lib/csc/list.csc deleted file mode 100644 index b1c2298..0000000 --- a/lib/csc/list.csc +++ /dev/null @@ -1,85 +0,0 @@ -(define-library (csc list) - (export - all - enumerate - filter - intercalate - revappend - split-at - take - unzip) - (import (scheme base) - (only (csc loop) - loop - return) - (only (csc match) - match)) - (begin - - - (define (take n xs) - (loop for x in xs - for i from 1 to n - collect x)) - - - (define (split-at n xs) - (if (<= n 0) - (values '() xs) - (loop for i from 1 to n - for x in xs - for second-half = (cdr xs) then (cdr second-half) - collect x into first-half - finally (return (values first-half second-half))))) - - - (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)))))) - - - (define (unzip l) - (loop for x in l - collect (car x) into xs - collect (cdr x) into ys - finally (return (values xs ys)))) - - - (define (all pred . ls) - (loop for ls = ls then (map cdr ls) - while (loop for l in ls - if (null? l) - return #f - finally (return #t)) - unless (apply pred (map car ls)) - return #f - finally (return #t))))) |
