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 π
list(n)lassign(n)ledit(n)lindex(n)linsert(n)llength(n)lmap(n)lpop(n)lrange(n)lremove(n)lrepeat(n)lreplace(n)lreverse(n)lsearch(n)lseq(n)lset(n)lsort(n)
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
- 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
- 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