Deutsch   English   Français   Italiano  
<1042vhu$3eavg$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 02:53:02 -0700
Organization: A noiseless patient Spider
Lines: 60
Message-ID: <1042vhu$3eavg$1@dont-email.me>
References: <1042r7u$3dr0l$1@dont-email.me> <1042u2q$3eaoi$1@dont-email.me>
 <1042uek$3dr0l$2@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 11:53:02 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="048938ceb69a34314b69bf9c47160de4";
	logging-data="3615728"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX18m7kWhRzyfB9qCjcIxG2lV"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:8QrjV5/8/sKp/kV2sh9AUQ+HDUA=
In-Reply-To: <1042uek$3dr0l$2@dont-email.me>
Content-Language: en-US

On 7/2/2025 2:34 AM, Mark Summerfield wrote:
> On Wed, 2 Jul 2025 11:27:54 +0200, Harald Oehlmann wrote:
> 
>> Am 02.07.2025 um 10:39 schrieb Mark Summerfield:
>>> proc process1 args {
>>>       set first [lindex $args 0]
>>>       puts "first='$first' args='$args' list? [string is list -strict $args]"
>>>       set rest [lrange $args 1 end]
>>>       puts "rest='$rest' list? [string is list -strict $rest]"
>>> }
>>
>> The name "args" is special in TCL returning all remaining arguments as a
>> list.
>>
>> As you call:
>> process1 $argv
>>
>> The one argument is put in a list. The result is a matrix (list in list).
>>
>> How to solve:
>>
>> a) don't use "args":
>>
>> proc process1 myargs {
>>         set first [lindex $myargs 0]
>>         puts "first='$first' args='$myargs' list? [string is list -strict
>> $myargs]"
>>         set rest [lrange $myargs 1 end]
>>         puts "rest='$rest' list? [string is list -strict $rest]"
>> }
>>
>> b) use the delist operator:
>>
>> process {*}$argv
>>
>> Hope this helps,
>> Harald
> 
> 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 :)


% proc p args {puts [list {*}$args]} ;# so an inverse of an inverse is an identity

% p 1 2 3
1 2 3

% p {1 2 3}
{1 2 3}

% p {1 2 3} {4 5 6}
{1 2 3} {4 5 6}

% p {*}{1 2 3}
1 2 3