aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2023-12-01 21:13:01 +0100
committerHugo Hörnquist <hugo@lysator.liu.se>2023-12-01 21:13:01 +0100
commit8cef70bf7a3925c44189487cceb7047ea603b3c9 (patch)
tree530dc44fe3774f88116752bdf84eba91b6af9309
parentImprove glob errors. (diff)
downloadcalp-8cef70bf7a3925c44189487cceb7047ea603b3c9.tar.gz
calp-8cef70bf7a3925c44189487cceb7047ea603b3c9.tar.xz
Add printer for tables.
Previsouly the underlying tree structure was exposed, as a nested set of scheme records. That was "unreadable", and rather unhelpfull, since table being trees is ONLY an implementation detail.
-rw-r--r--module/hnh/util/table.scm13
1 files changed, 11 insertions, 2 deletions
diff --git a/module/hnh/util/table.scm b/module/hnh/util/table.scm
index ebd5c8f7..23ce6cd4 100644
--- a/module/hnh/util/table.scm
+++ b/module/hnh/util/table.scm
@@ -24,14 +24,23 @@
(define-syntax-rule (symbol< args ...)
(string< (symbol->string args) ...))
-(define-type (tree-node)
+(define-type (tree-node
+ printer: (lambda (t p)
+ (write
+ `(-> (table)
+ ,@(fold (lambda (p done)
+ (cons `(table-put ,(car p) ,(cdr p))
+ done))
+ '()
+ (tree->list t)))
+ p)))
(key type: symbol?)
value
(left type: tree? default: (tree-terminal))
(right type: tree? default: (tree-terminal)))
;; Type tagged null
-(define-type (tree-terminal))
+(define-type (tree-terminal printer: (lambda (_ p) (write '(table) p))))
;; Wrapped for better error messages
(define (make-tree) (tree-terminal))