append(3tcl)

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

πŸŽ€ append β€” bestie, we're APPENDING πŸ’…

okay so this is append, a Tcl built-in command, and it is genuinely one of my faves. no cap.


✨ SYNOPSIS ✨

append varName ?value value value ...?

like. that's it. that's the whole vibe.


πŸ’– DESCRIPTION πŸ’–

So you've got a variable, right? varName. And you've got a bunch of value arguments. append takes every single one of those value args and sticks them onto the end of whatever varName is currently holding. boom. done. slay.

And if varName doesn't exist yet? No problem bestie, it just gets created, and its value becomes the concatenation of all the value arguments. iconic behaviour honestly.

🫢 Special case alert: if varName indicates an element that does not exist, of an array that has a default value set, then the concatenation of the default value and all the value arguments is what gets stored in the array element. noted. memorised. living rent free.

And the result of this command β€” like, what it actually returns β€” is the new value stored in variable varName. yes queen, give us the receipts.

Now the part that makes this command actually important: append is the efficient way to build up long variables incrementally. like, piece by piece, brick by brick. for example, append a $b is much more efficient than set a $a$b when $a is long. that's not me being dramatic, that's literally the manual. the way set a $a$b copies your whole long string around... πŸ’€ we don't do that.


🌸 EXAMPLE 🌸

Building a string of comma-separated numbers piecemeal, using a loop. very demure, very mindful:

set var 0
for {set i 1} {$i<=10} {incr i} {
    append var "," $i
}
puts $var
# Prints 0,1,2,3,4,5,6,7,8,9,10

look at her go πŸ¦‹ 0,1,2,3,4,5,6,7,8,9,10. ate and left no crumbs.


πŸ‘‘ SEE ALSO πŸ‘‘


⭐ KEYWORDS ⭐

append, variable


and that's the whole page, bestie πŸ’œ this one's from the Tcl built-in commands manual, page append(3tcl), and yes she's a keeper. go forth and concatenate responsibly. periodt. πŸ’…βœ¨

πŸ“¦ where this page comes from