diff options
author | Hugo Hörnquist <hugo@lysator.liu.se> | 2023-12-01 21:13:01 +0100 |
---|---|---|
committer | Hugo Hörnquist <hugo@lysator.liu.se> | 2023-12-01 21:13:01 +0100 |
commit | 8cef70bf7a3925c44189487cceb7047ea603b3c9 (patch) | |
tree | 530dc44fe3774f88116752bdf84eba91b6af9309 /module | |
parent | Improve glob errors. (diff) | |
download | calp-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.
Diffstat (limited to 'module')
-rw-r--r-- | module/hnh/util/table.scm | 13 |
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)) |