lappend(3tcl)

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

πŸ’– 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 πŸ’€

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