4 ms·
I've recently spent some time experimenting with Tcl, and I've developed some affection for it, but what tripped me up is that "everything is a string" means th
by pdw 6y ago
I've recently spent some time experimenting with Tcl, and I've developed some affection for it, but what tripped me up is that "everything is a string" means that Tcl is one of the few truly weakly typed languages. This Tcl notation:
{a b}
might represent any of the following data structures in JSON notation:
"a b"
["a", "b"]
[["a"], ["b"]]
{"a": "b"}
{"a": ["b"]}
This can make reading some Tcl code quite a puzzle.
- networked 6y agoGood observation. Tcl's {a b} also represents something not possible in JSON: {["a"]: ["b"]} The string a can be treated as "a", ["a"], [["a"]], [[["a"]]], ... by list operations.
- dkfellows 6y agoTechnically, Tcl's internal type system is that all other value types are subtypes of string, universally serializable to string, and will correctly round-trip through string. But it also means that you can type-pun stuff if you want; it just costs time. FWIW, the best handling I know of JSON in Tcl is the rl_json package (https://github.com/RubyLane/rl_json https://github.com/RubyLane/rl_json) which essentially makes JSON into what works like a native Tcl value type.