Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

The man on tops walks a lonely street; the "chain" of command is often a noose.


devel / comp.lang.tcl / Re: Length of a joined list

SubjectAuthor
* Length of a joined listSimon Geard
+- Re: Length of a joined listmango
`- Re: Length of a joined listRich

1
Length of a joined list

<u8n0vq$3cb0f$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=22382&group=comp.lang.tcl#22382

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: simon@whiteowl.co.uk (Simon Geard)
Newsgroups: comp.lang.tcl
Subject: Length of a joined list
Date: Wed, 12 Jul 2023 21:04:09 +0100
Organization: A noiseless patient Spider
Lines: 24
Message-ID: <u8n0vq$3cb0f$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 12 Jul 2023 20:04:11 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="94a3d399b4cc7b4a47f885d8ca2230cc";
logging-data="3550223"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+dUqLXp767Ov0TBSFLGdFE"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.13.0
Cancel-Lock: sha1:mIRTMiPTmga2HKjIQbiQOOYw1zE=
Content-Language: en-GB
 by: Simon Geard - Wed, 12 Jul 2023 20:04 UTC

Are all these results correct? To my simple mind the result should
always be 1 irrespective of the string used in the concatenation.

% set li {1 2 3}
1 2 3
% llength $li
3 % llength [join $li ,]
1 % llength [join $li \t]
3 % llength [join $li x]
1 % llength [join $li { }]
3 % llength [join $li {xox}]
1 % llength [join $li]
3

The man page doesn't seem to explain this inconsistency so I'm
struggling to understand it. Thanks for any ideas.

Simon

Re: Length of a joined list

<fd560ceb-dfac-48dd-9089-2cf80ad5291bn@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=22383&group=comp.lang.tcl#22383

  copy link   Newsgroups: comp.lang.tcl
X-Received: by 2002:ad4:551d:0:b0:635:dd39:e32 with SMTP id pz29-20020ad4551d000000b00635dd390e32mr82162qvb.5.1689193106177;
Wed, 12 Jul 2023 13:18:26 -0700 (PDT)
X-Received: by 2002:aca:bc54:0:b0:3a3:c78e:d863 with SMTP id
m81-20020acabc54000000b003a3c78ed863mr5766461oif.0.1689193105910; Wed, 12 Jul
2023 13:18:25 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!1.us.feeder.erje.net!feeder.erje.net!border-1.nntp.ord.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.tcl
Date: Wed, 12 Jul 2023 13:18:25 -0700 (PDT)
In-Reply-To: <u8n0vq$3cb0f$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=47.146.69.8; posting-account=ZFot6woAAABKx26r18WnGS2aDcK8wnRB
NNTP-Posting-Host: 47.146.69.8
References: <u8n0vq$3cb0f$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <fd560ceb-dfac-48dd-9089-2cf80ad5291bn@googlegroups.com>
Subject: Re: Length of a joined list
From: amangogna@modelrealization.com (mango)
Injection-Date: Wed, 12 Jul 2023 20:18:26 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 15
 by: mango - Wed, 12 Jul 2023 20:18 UTC

On Wednesday, July 12, 2023 at 1:04:16 PM UTC-7, Simon Geard wrote:
> Are all these results correct? To my simple mind the result should
> always be 1 irrespective of the string used in the concatenation.
[snip]
> The man page doesn't seem to explain this inconsistency so I'm
> struggling to understand it. Thanks for any ideas.
>
> Simon
The results are correct. The key to understanding is two fold. Lists in Tcl are just specially formatted strings. The join command creates a string from elements of a list. But, when llength is invoked on the join result (which is a string), it parses the string into a list. When the join is with a whitespace character (e.g. \t) then when llength parses the joined string, it finds that it looks just like a list. Mixing string operations, i.e. join, with list operations, i.e. llength, is often a recipe for confounding results. Printing out the intermediate join results may help you see that.

Re: Length of a joined list

<u8n7ga$3ctre$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=22384&group=comp.lang.tcl#22384

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: rich@example.invalid (Rich)
Newsgroups: comp.lang.tcl
Subject: Re: Length of a joined list
Date: Wed, 12 Jul 2023 21:55:22 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 63
Message-ID: <u8n7ga$3ctre$1@dont-email.me>
References: <u8n0vq$3cb0f$1@dont-email.me>
Injection-Date: Wed, 12 Jul 2023 21:55:22 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="7788db8cd204304c7a0dba880a8b5cb3";
logging-data="3569518"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+wpATjK8zUAvT4lpwIaEJ2"
User-Agent: tin/2.6.1-20211226 ("Convalmore") (Linux/5.15.19 (x86_64))
Cancel-Lock: sha1:Cv3IVT0qZ2+eBGxBzkqMGz/FxS8=
 by: Rich - Wed, 12 Jul 2023 21:55 UTC

Simon Geard <simon@whiteowl.co.uk> wrote:
> Are all these results correct? To my simple mind the result should
> always be 1 irrespective of the string used in the concatenation.
>
> % set li {1 2 3}
> 1 2 3
> % llength $li
> 3
> % llength [join $li ,]
> 1
> % llength [join $li \t]
> 3
> % llength [join $li x]
> 1
> % llength [join $li { }]
> 3
> % llength [join $li {xox}]
> 1
> % llength [join $li]
> 3
>
> The man page doesn't seem to explain this inconsistency so I'm
> struggling to understand it. Thanks for any ideas.
>
> Simon

To add to what mango said, the simplest string representation that Tcl
uses to represent a list as a string is simply to separate groups of
non-white space characters with a white space character (the actual
format is by far more complex, and describing it would only further
confuse you).

Add to that the fact that if you presently have a string, and ask for a
"list operation" to be performed on the string, Tcl will parse the
string into a list (if it can) or error out with an error message about
being unable to convert to list form.

Your first set is of a string, the string 1[space]2[space]3[space]
(where [space] means a single ASCII space character). Tcl's
string-to-list parser will convert that into a three eleement list if
you ask for "list operations" upon it.

So directly asking for the length results first in conversion to a
list, and then returning the length of the list, so you get three.

Joining with a comma however leaves no whitespace behind, so you get
1,2,3 which the parser then converts to a one element list, and you get
one as the answer.

The rest of the answers all follow by applying this rule to the
intermediate string that enters 'llength'. If there is whitespace,
multiple list elements result, if there is no whitespace, only one
list element results.

And, the warning mango gave is something to keep in mind. Mixing lists
and strings freely can be the source of weird data dependent bugs.
Things can work properly for months until just the right string comes
along to cause the string-to-list parser to error out.

It is much better to only use list commands on lists, only use string
commands on strings, and explicitly use the two conversion commands
(split and join) to convert one to the other yourself.


devel / comp.lang.tcl / Re: Length of a joined list

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor