lappend(3tcl)
π lappend β the manual page, but make it make sense π
okay bestie, so this is a page from the Tcl Built-In Commands manual (yes, the 3tcl one, we love her), and today's main character is lappend. Sit down, hydrate, let's go. π«Ά
β¨ NAME β¨
lappend β append list elements onto a variable. that's it. that's the whole job. slay. π
πΈ SYNOPSIS πΈ
lappend varName ?value value value ...?
π¦ DESCRIPTION π¦
so here's the vibe: this command looks at the variable named by varName and treats it like a list. then it takes every single one of the value arguments and appends each one onto that list as its own separate element, with spaces chilling between the elements. π
if varName doesn't exist yet? no worries, she gets created on the spot as a list whose elements are exactly the value arguments you passed. born yesterday, thriving today. β¨
and now the niche lil situation: if varName points at an element that doesn't exist, inside an array that has a default value set, then a list gets stored in that array element β and that list is made of the default value with all the value arguments appended onto it as elements. iykyk. π
lappend is giving very much "sister command" energy to append, except append just dumps raw text on there, while lappend is out here appending things as list elements. totally different energy, do not confuse them. π
it's also a genuinely efficient way to build up big lists, no cap. like, lappend a $b is much more efficient than set a [concat $a [list $b]] when $a is long. that's the whole reason she's iconic. π
π EXAMPLE π
using lappend to build up a list of numbers, bestie watch this:
% set var 1
1
% lappend var 2
1 2
% lappend var 3 4 5
1 2 3 4 5
ate. no crumbs. π₯
π SEE ALSO π
list(3tcl)lassign(3tcl)ledit(3tcl)lindex(3tcl)linsert(3tcl)llength(3tcl)lmap(3tcl)lpop(3tcl)lrange(3tcl)lremove(3tcl)lrepeat(3tcl)lreplace(3tcl)lreverse(3tcl)lsearch(3tcl)lseq(3tcl)lset(3tcl)lsort(3tcl)
the whole girl group, fr fr. π§
π KEYWORDS π
append, element, list, variable
lowkey a whole essay, but every single word of it matters, so don't skip. π
okay that's the page!! it came from the Tcl manual, it's the lappend(3tcl) page, and yeah β that's the source and the version tag, that's all she wrote. mwah, love u, go build a list. π
β¨πΈ
π¦ 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
- 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