Re: confused about lists and strings...

Liste des GroupesRevenir à cl tcl 
Sujet : Re: confused about lists and strings...
De : et99 (at) *nospam* rocketship1.me (et99)
Groupes : comp.lang.tcl
Date : 02. Jul 2025, 20:41:34
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <104421f$3mhhi$1@dont-email.me>
References : 1 2 3 4 5
User-Agent : Mozilla Thunderbird
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.

Date Sujet#  Auteur
2 Jul 25 * confused about lists and strings...8Mark Summerfield
2 Jul 25 `* Re: confused about lists and strings...7Harald Oehlmann
2 Jul 25  `* Re: confused about lists and strings...6Mark Summerfield
2 Jul 25   +* Re: confused about lists and strings...3et99
2 Jul 25   i`* Re: confused about lists and strings...2Rich
2 Jul 25   i `- Re: confused about lists and strings...1et99
2 Jul 25   +- Re: confused about lists and strings...1Rich
2 Jul 25   `- Re: confused about lists and strings...1Christian Gollwitzer

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal