These phrases let you store any kind of value in a JSON reference, but you have to manually track what kind it is:
JSON generic value type is a JSON type.
To decide which JSON reference is a/-- JSON value (V - value):
(- JSON_Create((+ JSON generic value type +), {V}) -).
To decide what K is (R - JSON reference) as a (name of kind of value K):
(- JSON_Read((+ JSON generic value type +), {R}) -).
To be used like this:
let D be JSON value 3 hours 15 minutes;
say "[D as a time][line break]";
I wonder if there’s a way to reliably turn every kind of value into a unique number… is there any way to get the name of a kind of value as a text? Or return the I6 kind number?
Well this works for any sayable kind, including objects, arithmetic values, scenes, external files, use options, etc:
To decide which JSON reference is a/-- JSON value (V - sayable value of kind K):
(- JSON_Create({-printing-routine:K}, {V}) -).
To decide what K is (R - JSON reference) as a (name of kind of sayable value K):
(- JSON_Read({-printing-routine:K}, {R}) -).
But the error message if you try to dereference it with the wrong kind doesn’t work, it says JSON type mismatch: expected <illegal json type>, got <illegal json type>
. We can’t get the name of every kind, but I could make it say JSON type mismatch: expected <illegal external file>, got <illegal scene>
. Better than nothing! Maybe with a little text editing we could remove the <illegal
part too. But for kinds without illegal values (like numbers), it would just print the number…
I feel like this is very promising… not needing to make phrases for all the different kinds makes a generic Collections extension much simpler to write and use.
type of (JSON reference)
won’t work with any of these, but we could have a phrase if type of (JSON reference) is (name of kind of sayable value K)
which probably covers most uses of it.