| Deutsch English Français Italiano |
|
<veht1v$t9io$1@dont-email.me> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Rich <rich@example.invalid>
Newsgroups: comp.lang.tcl
Subject: Re: tcl hidden "cruelties"
Date: Mon, 14 Oct 2024 01:44:31 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 44
Message-ID: <veht1v$t9io$1@dont-email.me>
References: <ve89ok$345h7$1@dont-email.me>
Injection-Date: Mon, 14 Oct 2024 03:44:31 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="cc5d4c666b466bfc5100f8b5eadc1ad0";
logging-data="960088"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19tI7iT0d00voryDRTvL0ZE"
User-Agent: tin/2.6.1-20211226 ("Convalmore") (Linux/5.15.139 (x86_64))
Cancel-Lock: sha1:bMjJgsIoj9c9SA+nokzETDGnPAA=
Bytes: 2367
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.
>
> namespace eval ::funcDEF::MkErrN {}
> array set ::funcDEF::MkErrN::my {
> RETURN_MAPPING {}
> ...
> }
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" whenever
you want to create a namespace, and then set an array within, i.e.:
% ns-array-set abc::pdq::xyz [list a 1 b 2 c 3]
Which has now, in a single command, created the parent namespaces, and
the array variable therein:
% info exists abc::pdq::xyz
1
% parray abc::pdq::xyz
abc::pdq::xyz(a) = 1
abc::pdq::xyz(b) = 2
abc::pdq::xyz(c) = 3
%
And, given that the 'array' command is itself a namespace ensemble, you
could extend the 'array' ensemble to add a "ns-set" (or whatever name
you like) to the ensemble that performs the above "create ns - and
init" of a namespace variable, then you could do
"array ns-set [list a 1 b 2]"
in your code to replace the two commands.