Skip to content

Instantly share code, notes, and snippets.

@carld
Created February 27, 2017 10:30
Show Gist options
  • Save carld/169ffeff738f114a2f4cdaa62cb4ee68 to your computer and use it in GitHub Desktop.
Save carld/169ffeff738f114a2f4cdaa62cb4ee68 to your computer and use it in GitHub Desktop.
Converting s-expressions (Lisp/Scheme) into Javascript (JSON)
(define (js-format l)
(cond
((null? l) "")
((not (list? (car l))) (string-append (format #f "'~a'" (car l))
(if (not (null? (cdr l)))
(string-append "," (js-format (cdr l)))
"")))
(else (string-append "\n[" (js-format (car l))
(if (not (null? (cdr l)))
(string-append "]," (js-format (cdr l)))
"]") ))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment