💾 Archived View for idiomdrottning.org › calltable-medea captured on 2023-11-14 at 08:33:22. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2023-01-29)

-=-=-=-=-=-=-

Call-tables and Medea

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)