23 ms·
FWIW, while in Tcl "everything is a string", that doesn't actually mean using things like numbers is slow. AIUI Tcl implementations actually use other datatypes
by eridius 9y ago
FWIW, while in Tcl "everything is a string", that doesn't actually mean using things like numbers is slow. AIUI Tcl implementations actually use other datatypes behind the scenes as well, it just matches the semantics of "everything is a string". So if you take the string "1" and treat it as a number, Tcl will basically turn it into a number behind the scenes so it doesn't have to re-parse that number every time it's used.
- cmacleod4 9y agoActually the "everything is (virtually) a string" approach has some beneficial effects. Keeping the underlying data structures compatible with this leads to using immutable values with copy-on-write, giving a very clean predictable semantics. I remember being shocked to discover that this did not apply in Python, where a value (not a variable) being used in one place can be modified by code elsewhere.
- majewsky 9y agoPerl does the same, by the way. A scalar variable can contain both a string and an integer representation. But as always, Perl takes the joke too far, by allowing variables to have incompatible string and integer representations simultaneously ("dual variables" in Perlspeak). For example, the variable $! is equivalent to C's `errno` when evaluated as an integer, but equivalent to `strerror(errno)` when evaluated as a string.