Hi Henrik,

>> convert all Ts to true, and NILs to false in the JSON string.

> With the NILs we run into a problem, because a property value of NIL
> means that this property does not exist. So it can never be
> extracted from the object itself.

maybe the js <-> picolisp mapping false <-> NIL is not the right thing
to do here?  There are things like undefined, null, "" (empty string),
NaN (maybe too?) or false you could represent as NIL but then you lose
information during conversion and cannot rebuild the js data back
again exactly.

> To solve the problem with the NILs, you'll have to keep a separate
> record of possible properties (as is done, for example, in the
> '+Entity' objects).

Or, you could create your own unique NIL which would be treated by
picolisp as any other non-NIL value and interpret it yourself during
picolisp -> javascript conversion as false, for example.

: (setq MyNIL (new))
(setq Tst (new))
(put Tst 'a "hello")
(put Tst 'b T)
(put Tst 'c MyNIL) # swap false, null, undefined or even NIL for MyNIL
(getl Tst)
(mapcar '((X) (or (pair X) (cons T X))) (getl Tst) )
   (prin "[")
   (for (I . X) (mapcar '((X) (or (pair X) (cons T X))) (getl Tst) )
      (when (< 1 I)
         (prin ", "))
      (prin (cdr X) ": ")
         ((== (car X) MyNIL) (prin "false"))
         ((== (car X) T) (prin "true"))
         (T (print (car X)))))
   (prin "]"))
-> $519715527
: -> $519715537
: -> "hello"
: -> T
: -> $519715527
: -> (($519715527 . c) b ("hello" . a))
: -> (($519715527 . c) (T . b) ("hello" . a))
: [c: false, b: true, a: "hello"]-> "]"

This is oversimplified version as there are lots of special cases in
javascript to handle, e.g. you have to double-quote keys if they are
negative numbers if I remember well:

["-1": "negative numbers as strings in key"]

Alex, why does getl return a list of (property-value . property-name)
and not a list of (property-name . property-value)?



Reply via email to