Re:The Tcl Programming Language: A Comprehensive Guide (2nd ...
by coliveira on Friday April 04, 2025 @05:52PM
(#43588017)
There is no big difference between TCL and other languages like Python in this respect. Yes, TCL stores everything as a string, but it also assigns a type when the data is used. If you need a defined type, you can use structures; there are even classes/objects available as packages.
[ Parent
| on HN ]
Re:The Tcl Programming Language: A Comprehensive Guide (2nd ...
by 7thaccount on Friday April 04, 2025 @06:48PM
(#43588555)
Does it still do this? I thought they changed this many years ago?
Re:The Tcl Programming Language: A Comprehensive Guide (2nd ...
by smj-edison on Friday April 04, 2025 @07:32PM
(#43588841)
Yep! It's called shimmering. The way it works is it has a string and internal representation. When the internal representation is modified it invalidates the string version. If the string version is needed later it'll regenerate the string representation. That way it can always be used as a string, but internally it is pretty efficient when it stays as the same type.
Re:The Tcl Programming Language: A Comprehensive Guide (2nd ...
by remram on Friday April 04, 2025 @06:00PM
(#43588096)
That is absolutely not how Python works. Python values are typed.
Re:The Tcl Programming Language: A Comprehensive Guide (2nd ...
by apgwoz on Friday April 04, 2025 @06:11PM
(#43588232)
> "a dynamically typed language is a statically typed language with only one static type."
— Bob Harper
Re:The Tcl Programming Language: A Comprehensive Guide (2nd ...
by remram on Friday April 04, 2025 @06:18PM
(#43588300)
Yes but we are not talking about static types...
Re:The Tcl Programming Language: A Comprehensive Guide (2nd ...
by apgwoz on Friday April 04, 2025 @06:26PM
(#43588374)
You’re misunderstanding. Dynamic languages inherently have a single type that is checked _at runtime_. Store it in a string, store it in a struct. It doesn’t matter.
Re:The Tcl Programming Language: A Comprehensive Guide (2nd ...
by layer8 on Friday April 04, 2025 @06:56PM
(#43588628)
The runtime values have tags that denote their runtime type. They are not of a single type. You are talking about static types.
Re:The Tcl Programming Language: A Comprehensive Guide (2nd ...
by apgwoz on Friday April 04, 2025 @09:26PM
(#43589560)
And in Tcl the runtime type is computed at time of use. An optimized Tcl could cache an integer with a string that represents an int to avoid that cost.
Nevertheless, a runtime type tag is an optimization. That doesn’t make Bob’s statement any less true.
Re:The Tcl Programming Language: A Comprehensive Guide (2nd ...
by remram on Friday April 04, 2025 @11:09PM
(#43590326)
What you said above is correct but is not related to what was being discussed before.
Re:The Tcl Programming Language: A Comprehensive Guide (2nd ...
by apgwoz on Saturday April 05, 2025 @02:45AM
(#43591433)
How is it not related?
Because Python is “strong typed” vs “weak typed” for Tcl?
$ tclsh8.6
% expr 1 + 2
3
% expr 3 + “hey there”
invalid bareword “hey”
in expression “1 + hey there”;
should be “$hey” or “{hey}” or “hey(…)” or …
vs. $ python3.11
>>> 1 + 2
3
>>> 1 + “hey there”
Traceback (most recent call last):
File “<stdin>”, line 1, in <module>
TypeError: unsupported operand type(s) for +: ‘int’ and ‘str’
I don’t really see a difference. Both checked types at runtime. Clearly Tcl can check types at runtime, even though it represents everything as a string. Whether all commands do so is another story. But, not all functions in Python check types before trying to do things that don’t make sense, either. So…
Re:The Tcl Programming Language: A Comprehensive Guide (2nd ...
by bombarolo on Saturday April 05, 2025 @11:41AM
(#43594303)
I can see a difference that I can understand the Python’s error message, the Tcl’s one not so much.