💾 Archived View for idiomdrottning.org › calltable-medea captured on 2024-05-10 at 11:34:52. Gemini links have been rewritten to link to archived content
⬅️ Previous capture (2023-01-29)
-=-=-=-=-=-=-
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)