Name: Anonymous 2012-11-10 7:02
How do you transform/encode a generic s-exp to JSON and back?
inb4 "very carefully."
inb4 "very carefully."
(define (to-json exp) ...)hash = {"a": [1, 42], "b": 2}
(@
a (1 42)
b 2)
a, and the value (cdr) is still '(1 42). The real issue is you can't tell the difference between [[1, 2], [3, 4]] and {1: [2], 3: [4]}. json-hash datatype yourself, and use regular pairs for Arrays, depending on which LISP you're using.
{
"key1":[29,"val",2],
"key2":51,
"key3":{"key3.1":[{},{}], "key3.2":32}
}
(hash
("key1" (array 29 "val" 2))
("key2" 51)
("key3" (hash ("key3.1" (array (hash) (hash))) ("key3.2" 32)))
)
(define (factorial n)
(letr loop ((n n) (acc 1))
(if (= n 0)
acc
(loop (- n 1) (* n acc)))))
["define",["factorial","n"],
["letr","loop",[["n","n"],["acc", 1]],
["if",["=","n",0],
"acc",
["loop",["-","n",1],["*","n","acc"]]]]]
'(#hash((key . 1)) 1 2)