llength(n)
๐ 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:
list(n)lappend(n)lassign(n)ledit(n)lindex(n)linsert(n)lmap(n)lpop(n)lrange(n)lremove(n)lrepeat(n)lreplace(n)lreverse(n)lsearch(n)lseq(n)lset(n)lsort(n)
โญ 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
- alpine 3.23: tcl9-doc 9.0.3-r0 ยท TCL
- alpine 3.24: tcl9-doc 9.0.3-r2 ยท TCL
- fedora 43: tcl-doc 1:9.0.2-1.fc43 ยท TCL AND GPL-3.0-or-later WITH Bison-exception-2.2 AND BSD-3-Clause
- fedora 44: tcl-doc 1:9.0.2-1.fc44 ยท TCL AND GPL-3.0-or-later WITH Bison-exception-2.2 AND BSD-3-Clause
- nixos 26.05: tcl 9.0.3
- nixpkgs unstable: tcl 9.1.0
- Copyright (c) 1993 The Regents of the University of California
- Copyright (c) 1994-1996 Sun Microsystems, Inc
- Copyright (c) 2001 Kevin B. Kenny <kennykb@acm.org>. All rights reserved
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms