aboutsummaryrefslogtreecommitdiffstats
path: root/util.scm
diff options
context:
space:
mode:
authorGravatar Peter McGoron 2024-09-08 08:22:39 -0400
committerGravatar Peter McGoron 2024-09-08 08:22:39 -0400
commit8bee2d39a43b589654a2067ff3385a33059fd308 (patch)
tree3b99603d5e01495600e692ce86b9184cfcc43043 /util.scm
parentreadtable: case folding (diff)
readtable: simplify
After taking a look at the R7RS syntax and how Chicken parses directives, I realized that it's easier to have "#!", "#\\", etc. parse identifiers instead of baking in trie actions. This is slightly slower but completely removes the trie concept from the readtable, which simplifies the implementation and removes many corner cases involving combining readtables with different action types.
Diffstat (limited to 'util.scm')
-rw-r--r--util.scm15
1 files changed, 15 insertions, 0 deletions
diff --git a/util.scm b/util.scm
index fa361f7..cf1fe2e 100644
--- a/util.scm
+++ b/util.scm
@@ -33,3 +33,18 @@
((not (f (car lst))) #f)
(else (all f (cdr lst))))))
+;;; (REVAPPEND L1 ... LN) returns L{N-1}, L{N-2}, ... reversed and
+;;; appended to LN, in that order.
+(define revappend
+ (letrec ((loop
+ (lambda (lst1 lst2)
+ (if (null? lst1)
+ lst2
+ (loop (cdr lst1) (cons (car lst1) lst2))))))
+ (lambda lists
+ (cond
+ ((null? lists) '())
+ ((null? (cdr lists)) (car lists))
+ (else
+ (apply revappend (loop (car lists) (cadr lists))
+ (cddr lists)))))))