Sujet : Re: tcl hidden "cruelties"
De : rich (at) *nospam* example.invalid (Rich)
Groupes : comp.lang.tclDate : 14. Oct 2024, 19:13:51
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vejn0u$1a2ms$1@dont-email.me>
References : 1 2 3
User-Agent : tin/2.6.1-20211226 ("Convalmore") (Linux/5.15.139 (x86_64))
aotto1968 <
aotto1968@t-online.de> wrote:
On 14.10.24 03:44, Rich wrote:
aotto1968 <aotto1968@t-online.de> wrote:
Regardless of "broken code", TCL itself has some cruelties in its
syntax. Here, for example, the storage of an "array" with a
namespace path, which in TCL always has !! TWO !! commands. ONE
command to generate the namespace and ONE command to finally generate
the array.
This is Tcl. If something is that bothersome, just morph the language
to be the way you want it to work. I.e.:
proc ns-array-set {fullvarname contents} {
namespace eval [namespace qualifiers $fullvarname] {}
array set $fullvarname $contents
}
Create that once, then use it, instead of plain "array set" ...
your hint with the "ensemble" feature was good but missing the required code.
Yes, I left that exercise to the reader to work out.
to "extend" an ensemble is quite complicate in TCL… follow the code below:
As are most /things/ in most programming languages.
1) but the CORE problem is not solved, for every "namespace ns-set
..." command TWO commands are executed just to avoid FIRST namespace
missing error. → (ALL pay runtime-speed just for FIRST benefit)
You'll pay that runtime no matter whether it appears as one, or two,
commands in your source. The 'work' of checking if the namespace
exists, and then creating it when it does not, has to be paid, no
matteer how many 'commands' appear in the Tcl script.
2) the syntax to extend an existing ensemble is still very "ugly.."
improvement:
1. namespace ensemble add array ns-set ::array-ns-set
2. namespace ensemble delete array ns-set
You can 'wrap' that ugliness into your own proc, and 'extend' the
namespace ensemble itself, to remove that as well if you like.