From 8cef70bf7a3925c44189487cceb7047ea603b3c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Fri, 1 Dec 2023 21:13:01 +0100 Subject: 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. --- module/hnh/util/table.scm | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'module/hnh') 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)) -- cgit v1.2.3