lappend(n)

✨ lappend(n) β€” the Tcl glow-up for your lists ✨

okay bestie, gather round, because this little built-in is about to become your whole personality πŸ’– it lives in the Tcl Built-In Commands fam and honestly? it's giving main character energy.


🌸 NAME 🌸

lappend β€” append list elements onto a variable πŸŽ€


πŸ¦‹ SYNOPSIS πŸ¦‹

lappend varName ?value value value ...?

πŸ’… DESCRIPTION πŸ’…

So here's the vibe: this command takes the variable named by varName and treats it like a list, then appends each one of the value arguments onto that list as its own separate element, with spaces chillin' between the elements. ✨

If varName doesn't even exist yet? No worries, bestie β€” it gets created as a list with the elements you handed over in the value arguments. Lowkey magical. πŸͺ„

And if varName points at an element that doesn't exist of an array that has a default value set, then a list that is comprised of the default value with all the value arguments appended as elements will be stored in the array element. (iykyk β€” arrays keep their secrets πŸ’€)

lappend is similar to append, except that the values get appended as list elements rather than as raw text. That's the whole plot twist. πŸ™ˆ

Also? This command is a relatively efficient way to build up large lists. Like, for real: lappend a $b is much more efficient than set a [concat $a [list $b]] when $a is long. no cap. πŸ”₯


⭐ EXAMPLE ⭐

Using lappend to build up a list of numbers:

% set var 1
1
% lappend var 2
1 2
% lappend var 3 4 5
1 2 3 4 5

ate. πŸ‘‘


πŸ‘‘ SEE ALSO πŸ‘‘

the whole list-girlie friend group, together at last 🫢


πŸ“ KEYWORDS πŸ“

append, element, list, variable


πŸ’œ reminder: keep every option and value exactly as written β€” this page is cute but the details are sacred.

okay that's the whole page, and if you made it to the end, you're literally the icon of this manual 🧚

with love from Tcl πŸ’– β€” signing off on lappend(n), date and all, mwah πŸ’…βœ¨

πŸ“¦ where this page comes from