diff options
author | Hugo Hörnquist <hugo@lysator.liu.se> | 2019-03-22 20:11:11 +0100 |
---|---|---|
committer | Hugo Hörnquist <hugo@lysator.liu.se> | 2019-03-22 20:17:52 +0100 |
commit | d46183860c1f3f10095e95023adcb79b1896ab0e (patch) | |
tree | dd331a0efe9777bfe84160139da1e39df3226b71 /helpers.scm | |
parent | Add stuff to test.scm. (diff) | |
download | calp-d46183860c1f3f10095e95023adcb79b1896ab0e.tar.gz calp-d46183860c1f3f10095e95023adcb79b1896ab0e.tar.xz |
Move C and Scheme code into subdirs.
Diffstat (limited to 'helpers.scm')
-rw-r--r-- | helpers.scm | 43 |
1 files changed, 0 insertions, 43 deletions
diff --git a/helpers.scm b/helpers.scm deleted file mode 100644 index 717a10d4..00000000 --- a/helpers.scm +++ /dev/null @@ -1,43 +0,0 @@ -(use-modules (srfi srfi-1) - (srfi srfi-8) ; receive - ) - -(define (nlist? l) - "Returns #t if l is a pair that is not a list." - (and (pair? l) - (not (list? l)))) - -(define (flatten tree) - "Flattens tree, should only return propper lists." - (cond ((null? tree) '()) - ((list? tree) - (if (null? (cdr tree)) - (flatten (car tree)) - (let ((ret (cons (flatten (car tree)) - (flatten (cdr tree))))) - (if (nlist? ret) - (list (car ret) (cdr ret)) - ret)))) - (else tree))) - - -(define (map-lists f lst) - "Map f over lst, if (car lst) is a list, pass the list to f. If (car list) -isn't a list, pass the rest of lst to f." - (cond ((null? lst) '()) - ((list? (car lst)) (cons (f (car lst)) - (map-lists f (cdr lst)))) - (else (f lst)))) - -(define (beautify tree) - "Takes a prefix tree and turns some characters to strings." - (define (helper branch) - (receive (head tail) - (span char? branch) - (cons (list->string head) - (beautify tail)))) - (if (or (null? tree) - (not (list? tree))) - tree - (cons (beautify (car tree)) - (map-lists helper (cdr tree))))) |