💾 Archived View for idiomdrottning.org › calltable-medea captured on 2023-01-29 at 03:55:21. Gemini links have been rewritten to link to archived content
-=-=-=-=-=-=-
Here’s a simple way to write JSON from call-tables. It’s very unoptimal for now since it uses an intermediate representation instead of writing directly:
(import brev-separate medea srfi-69) (json-unparsers `((,symbol? . ,(o write symbol->string)) (,call-table*? . ,(fn (write-json ((over (cons (car x) (list->vector (cdr x)))) (hash-table->alist (x)))))) (,call-table? . ,(fn (write-json (hash-table->alist (x))))) ,@(json-unparsers)))
It makes writing them straight-forward:
(define fruit-color (ctq* apple red pear (green yellow))) (write-json fruit-color)