lpop(n)
okay bestie, welcome to lpop(n), the Tcl Built-In Commands page that's literally about grabbing an element out of a list and deleting it at the same time. main character energy fr. let's get into it. π«Άβ¨
β¨ NAME β¨
lpop β Get and remove an element in a list π
π SYNOPSIS π
lpop varName ?index ...?
π DESCRIPTION π
The lpop command takes a parameter, varName, and is like "bestie, I'm treating this as the name of a variable that holds a Tcl list." It also takes one or more indices into that list. If you don't pass any indices, it defaults to "end". periodt.
When you give it a single index, lpop addresses the index'th element in the list, removes it from the list, and returns that element. It's giving pop but for Tcl lists, no cap.
If index is negative, or greater than or equal to the number of elements in the list in the variable called varName, an error occurs. so don't try it unless you want chaos. π
The interpretation of each simple index value is the same as for the command string index, supporting simple index arithmetic and indices relative to the end of the list. iykyk.
If additional index arguments are supplied, then each argument is used in turn to address an element within a sublist designated by the previous indexing operation. This lets the script remove elements in sublists, similar to lindex and lset. The command,
lpop a 1 2
gets and removes element 2 of sublist 1. obsessed.
π EXAMPLES π
In each of these examples, the initial value of x is:
set x [list [list a b c] [list d e f] [list g h i]]
β {a b c} {d e f} {g h i}
The indicated value becomes the new value of x (except in the last case, which is an error which leaves the value of x unchanged.)
lpop x 0
β {d e f} {g h i}
lpop x 2
β {a b c} {d e f}
lpop x end
β {a b c} {d e f}
lpop x end-1
β {a b c} {g h i}
lpop x 2 1
β {a b c} {d e f} {g i}
lpop x 2 3 j
β list index out of range
In the following examples, the initial value of x is:
set x [list [list [list a b] [list c d]] \
[list [list e f] [list g h]]]
β {{a b} {c d}} {{e f} {g h}}
The indicated value becomes the new value of x.
lpop x 1 1 0
β {{a b} {c d}} {{e f} h}
π SEE ALSO π
list(n)lappend(n)lassign(n)ledit(n)lindex(n)linsert(n)llength(n)lmap(n)lrange(n)lremove(n)lrepeat(n)lreplace(n)lreverse(n)lsearch(n)lseq(n)lset(n)lsort(n)string(n)
π₯ KEYWORDS π₯
element, index, list, remove, pop, stack, queue
okay that's the whole vibe. this page is from Tcl 9.0, and it's the lpop(n) manual page, so go pop some list elements responsibly, bestie. π
β¨
π¦ 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) 2018 Peter Spjuth. All rights reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms