append(3tcl)
π 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: ifvarNameindicates an element that does not exist, of an array that has a default value set, then the concatenation of the default value and all thevaluearguments 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
- debian trixie: tcl9.0-doc 9.0.1+dfsg-2
- ubuntu questing: tcl9.0-doc 9.0.2+dfsg-1
- ubuntu resolute: tcl9.0-doc 9.0.3+dfsg-1
- ubuntu stonking: tcl9.0-doc 9.0.4+dfsg-1
- Copyright (c) 1993 The Regents of the University of California
- Copyright (c) 1994-1996 Sun Microsystems, Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms