| Deutsch English Français Italiano |
|
<104421f$3mhhi$1@dont-email.me> View for Bookmarking (what is this?) Look up another Usenet article |
Path: news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail
From: et99 <et99@rocketship1.me>
Newsgroups: comp.lang.tcl
Subject: Re: confused about lists and strings...
Date: Wed, 2 Jul 2025 12:41:34 -0700
Organization: A noiseless patient Spider
Lines: 35
Message-ID: <104421f$3mhhi$1@dont-email.me>
References: <1042r7u$3dr0l$1@dont-email.me> <1042u2q$3eaoi$1@dont-email.me>
<1042uek$3dr0l$2@dont-email.me> <1042vhu$3eavg$1@dont-email.me>
<1043a7i$3h3vi$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 02 Jul 2025 21:41:36 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="048938ceb69a34314b69bf9c47160de4";
logging-data="3884594"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX184P8JJfRgtpB/WvDBBq01Y"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:SUo3uqGx8UWoHcGWpVtbvaAKWCc=
Content-Language: en-US
In-Reply-To: <1043a7i$3h3vi$1@dont-email.me>
On 7/2/2025 5:55 AM, Rich wrote:
> et99 <et99@rocketship1.me> wrote:
>> On 7/2/2025 2:34 AM, Mark Summerfield wrote:
>>> Thanks, I hadn't realised that using `args` would give me a list in a list.
>>> I now just pass the list as-is (and called `rest` to avoid confusion!).
>>
>> This used to confuse me totally. Now I understand (I think) that
>> args and {*} are inverses of each other. If you can get your head
>> around this, then you got it :)
>
> If you understand what 'xargs' does on a Unix CLI, {*} is essentially a
> "Tcl xargs".
>
> It (when used for calling a proc) converts "a list of things" into
> "individual parameters to the proc".
>
> What it really does is "unwraps" the lists contents. So instead of
> having "one list containing 5 things" you end up with the internal "5
> things" each individually.
>
>
Yes, it was your explanation, some years back which opened my brain to {*}.
One pleasant implementation detail I discovered, is that {*}{} does not produce an argument, which is useful in say, passing in some optional arguments that are then passed into the middle of some other command, such as lsort, for example:
proc mysort {alist args} {
....
lsort {*}$args $alist
....
}
If args is null, then lsort only sees one arg; no need to test for args being null.