lpop(n)

πŸ“¦
version 9.0.3 Β· 2 versions
, in alpine 3.23, alpine 3.24, fedora 43, fedora 44, nixos 26.05

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 πŸ‘€

πŸ”₯ 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