| Deutsch English Français Italiano |
|
<veihug$13uq8$1@dont-email.me> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!weretis.net!feeder8.news.weretis.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: aotto1968 <aotto1968@t-online.de>
Newsgroups: comp.lang.tcl
Subject: Re: tcl hidden "cruelties"
Date: Mon, 14 Oct 2024 09:41:04 +0200
Organization: A noiseless patient Spider
Lines: 71
Message-ID: <veihug$13uq8$1@dont-email.me>
References: <ve89ok$345h7$1@dont-email.me> <veht1v$t9io$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Mon, 14 Oct 2024 09:41:05 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="99ed8f2dc5d57fc8463e9e291a95e614";
logging-data="1178440"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/JwHGXStCkr32gZ0vnboxp5HCHHnBnPVs="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:HJTyOzbpeNbJ5rmloiiusHUEYpY=
Content-Language: en-US
In-Reply-To: <veht1v$t9io$1@dont-email.me>
Bytes: 3588
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.
>>
>> 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.
>
your hint with the "ensemble" feature was good but missing the required code.
to "extend" an ensemble is quite complicate in TCL… follow the code below:
proc ::array-ns-set {fullvarname contents} {
namespace eval [namespace qualifiers $fullvarname] {}
array set $fullvarname $contents
}
namespace ensemble configure array -map [dict replace \
[namespace ensemble configure array -map] ns-set ::array-ns-set]
array ns-set ::x::my [list a 1 b 2]
parray ::x::my
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)
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