llength(n)

๐Ÿ“ฆ
version 9.0.3 ยท 2 versions
, in alpine 3.23, alpine 3.24, fedora 43, fedora 44, nixos 26.05, nixpkgs unstable

๐Ÿ’– llength(n) โ€” the Tcl Built-In Commands glow-up ๐Ÿ’–

okay bestie, gather round, because today we're counting. not like, counting your exes, counting list elements. this little cutie lives in the Tcl Built-In Commands manual, section n, and it's about to become your whole personality. no cap. ๐ŸŽ€


โœจ NAME โœจ

llength โ€” count the number of elements in a list ๐Ÿงฎ


๐ŸŒธ SYNOPSIS ๐ŸŒธ

llength list

๐Ÿฆ‹ DESCRIPTION ๐Ÿฆ‹

so here's the tea, and the tea is simple: llength treats list as a list (iconic of it) and hands you back a decimal string giving the number of elements in it. that's it. that's the whole job. and it eats every single time. ๐Ÿ’…

like, it's not returning an integer object or whatever, it's a decimal string, and honestly? we respect the commitment to the bit.


๐Ÿ”ฅ EXAMPLES ๐Ÿ”ฅ

first up: the result is the number of elements. obviously. the way it just works:

% llength {a b c d e}
5
% llength {a b c}
3
% llength {}
0

look at that. {} gives you 0, because an empty list has zero elements, and llength is not out here playing games. โœจ


now, important lore: elements are not guaranteed to be exactly words in a dictionary sense of course, especially when quoting is used. so like, don't come for the list when it counts things the way it counts them, bestie:

% llength {a b {c d} e}
4
% llength {a b { } c d e}
6

see what happened there? {c d} is ONE element, not two. and { } is also ONE element, even though it looks like a whole lotta nothing. the vibes are immaculate, the counting is correct. ๐Ÿ™ˆ


and final plot twist, because this one gets people every time: an empty list is not necessarily an empty string. not me learning this the hard way:

% set var { }; puts "[string length $var],[llength $var]"
1,0

one character. zero elements. string length said 1, llength said 0, and they're both right. main character energy from two commands at once, honestly. ๐Ÿ‘‘


๐ŸŒˆ SEE ALSO ๐ŸŒˆ

the whole squad, all of them, no one left behind:


โญ KEYWORDS โญ

element, list, length โ€” that's the whole vibe check, iykyk. ๐Ÿซถ


๐Ÿ’€ friendly reminder: none of the above is me guessing, it's literally all in the page. llength counts elements, returns a decimal string, and quoting changes what counts as one element. periodt.

that's the page, bestie!! this one came straight from the Tcl manual, llength(n), and it's giving "small command, huge impact." go forth and count your elements. slay. ๐Ÿ’œ๐Ÿฆ‹๐ŸŽ€โœจ๐Ÿ’…

๐Ÿ“ฆ where this page comes from