RodionGork
2024-08-16 07:10:30 UTC
Hi Friends!
Still making my first feeble steps in TCL so please excuse me if this is
naive or was asked multiple times.
Attempt to fetch by non-existing key in "associative array" results in
error, e.g.
set a(1) 5
puts $a(2) ;# yields error
the workaround seems to be [info exists ::a(2)] which feels a bit remote
from other "array" commands.
Is there some motivation why some command for get-with-default is not
implemented, e.g.
puts [array peek $a 2 "default value"]
Popular use-case for this would be creating map where elements are
updated (like counter of words etc) - though I found this is cleverly
covered by "incr" and "append" commands properly behaving
when element to be incremented or appended does not exist yet.
But I suspect there are other situations when such a command may be
handy.
Also why [array exists ...] command does not exist (while [dict exists
..] does)? Perhaps there is something about no good syntax for it due
to how arrays are implemented?
Still making my first feeble steps in TCL so please excuse me if this is
naive or was asked multiple times.
Attempt to fetch by non-existing key in "associative array" results in
error, e.g.
set a(1) 5
puts $a(2) ;# yields error
the workaround seems to be [info exists ::a(2)] which feels a bit remote
from other "array" commands.
Is there some motivation why some command for get-with-default is not
implemented, e.g.
puts [array peek $a 2 "default value"]
Popular use-case for this would be creating map where elements are
updated (like counter of words etc) - though I found this is cleverly
covered by "incr" and "append" commands properly behaving
when element to be incremented or appended does not exist yet.
But I suspect there are other situations when such a command may be
handy.
Also why [array exists ...] command does not exist (while [dict exists
..] does)? Perhaps there is something about no good syntax for it due
to how arrays are implemented?
--
to email me substitute github with gmail please
to email me substitute github with gmail please