On Friday, January 28, 2022 at 2:06:05 PM UTC+1, Andreas Leitgeb wrote:
Nope, note the refcount 7. Always start such tests in a fresh tclsh - or even better in a file.
But even in a fresh tclsh, I can reproduce the string rep ... and demonstrate how Tcl re-uses objects.
$ tclsh
% tcl::unsupported::representation [dict create foo bar]
value is a dict with a refcount of 3, object pointer at 0x10306b0, internal representation 0x10afad0:(nil), string representation "foo bar"
% tcl::unsupported::representation [dict create foo bar]
value is a dict with a refcount of 4, object pointer at 0x10306b0, internal representation 0x10afad0:(nil), string representation "foo bar"
% tcl::unsupported::representation [dict create foo bar]
value is a dict with a refcount of 5, object pointer at 0x10306b0, internal representation 0x10afad0:(nil), string representation "foo bar"
% tcl::unsupported::representation [dict {*}{create foo bar}]
value is a dict with a refcount of 6, object pointer at 0x10306b0, internal representation 0x10afad0:(nil), string representation "foo bar"
% tcl::unsupported::representation [dict {*}{create foo bar}]
value is a dict with a refcount of 7, object pointer at 0x10306b0, internal representation 0x10afad0:(nil), string representation "foo bar"
% tcl::unsupported::representation [dict {*}{create foo baz}]
value is a dict with a refcount of 3, object pointer at 0x10cc9e0, internal representation 0x10b18d0:(nil), string representation "foo baz"
Your special case seems to be crafted by the interactive mode - not even non-normalized string reps in the command could break that.
But the interpreter on its own behaves as expected:
$ cat test.tcl
set a [dict create foo 1 bar 2]
puts [tcl::unsupported::representation $a]
puts $a
puts [tcl::unsupported::representation $a]
puts [tcl::unsupported::representation {foo 1 bar 2}]
$ tclsh test.tcl
value is a dict with a refcount of 2, object pointer at 0x10d0610, internal representation 0x10e9ec0:(nil), no string representation
foo 1 bar 2
value is a dict with a refcount of 2, object pointer at 0x10d0610, internal representation 0x10e9ec0:(nil), string representation "foo 1 bar 2"
value is a pure string with a refcount of 1, object pointer at 0x10d0eb0, string representation "foo 1 bar 2"