concat(3tcl)

πŸ“¦
version 9.0.4 Β· 2 versions
, in debian trixie, ubuntu questing, ubuntu resolute, ubuntu stonking

πŸ’– concat β€” the Tcl built-in that's literally just "glue lists together" πŸ’–

okay bestie, welcome to concat(3tcl), one of the Tcl Built-In Commands, and ngl she's lowkey one of the most underrated icons in the whole toolkit 🫢


✨ SYNOPSIS ✨

concat ?arg arg ...?

🌸 DESCRIPTION 🌸

So here's the tea, bestie: this command takes each of its arguments and joins them together with spaces, after trimming leading and trailing white-space from each of them. Periodt. βœ‚οΈ

And if all of the arguments happen to be lists? Then it's giving the exact same energy as concatenating them into a single list. No cap. πŸŽ€

Arguments that are empty (after trimming, obvs) get ignored entirely β€” like, they're not even invited to the function. πŸ™ˆ

It permits any number of arguments, she's flexible like that πŸ’…. And if you supply no args at all? The result is an empty string. That's it, that's the whole vibe.


πŸ¦‹ EXAMPLES πŸ¦‹

Okay so even though concat will concatenate lists and flatten them in the process (so giving the following interactive session):

% concat a b {c d e} {f {g h}}
a b c d e f {g h}

...it will also concatenate things that are not lists, as can be seen from this session:

% concat " a b {c   " d "  e} f"
a b {c d e} f

Note also that the concatenation does not remove spaces from the middle of values, as can be seen here:

% concat "a   b   c" { d e f }
a   b   c d e f

(i.e., there are three spaces between each of the a, the b and the c πŸ‘€ yes really, count them, she said what she said)


πŸ’œ so when do I actually want real list concatenation tho?

For true list concatenation, the list command should be used with expansion of each input list:

% list {*}"a   b   c" {*}{ d e f }
a b c d e f

see how the extra spaces got ate?? list + {*} is the moment, fr fr πŸ”₯


πŸ‘‘ SEE ALSO πŸ‘‘


⭐ KEYWORDS ⭐

concatenate, join, list


and that's the whole page bestie!! this one came straight out of Tcl 8.3 and it's dated right there in the concat(3tcl) footer, so if you're running something ancient or something brand new, now you know where she came from 🧚 mwah, go flatten some lists, you've got this πŸ’–βœ¨πŸŽ€

πŸ“¦ where this page comes from