Sujet : Re: a typeof command for debugging?
De : auriocus (at) *nospam* gmx.de (Christian Gollwitzer)
Groupes : comp.lang.tclDate : 21. Jun 2025, 14:51:31
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <1036dd3$13c9j$1@dont-email.me>
References : 1
User-Agent : Mozilla Thunderbird
Am 21.06.25 um 13:16 schrieb Mark Summerfield:
I'd like a `typeof` command for debugging.
I've had a go but only bits of it work.
```
proc typeof x {
if {![catch {[info object class $x] name}]} {
return $name
} else {
if {[string is boolean -strict $x]} {
return bool
[...]
I don't think you can do much better than that, since Tcl is a weakly typed language (usually referred to as the "EIAS" principle). The only other thing you can do is peek into the internal cached type, which shows you the last type that was used on that object (besides string):
(chris) 50 % set a [expr {23*5}]
115
(chris) 51 % tcl::unsupported::representation $a
value is a int with a refcount of 4, object pointer at 0x55d6b8f8b320, internal representation 0x73:(nil), string representation "115"
Christian