lpopTcl 9.1 only
Removes an element from the list in a variable and gives it.
lpop VAR ?INDEX ...?
Description
Removes the element at INDEX from the list in the variable VAR, and gives that element. The default INDEX is end, so lpop with no INDEX removes the last element. Each further INDEX goes one level down into a nested list, and one INDEX that is a list of indexes is the same path.
The index must be an element of the list: an empty list, or an index out of range, is an error, and VAR keeps its value. VAR must have a value.
Arguments
| Argument | Type | Default | Description |
|---|---|---|---|
| VAR | variable name | required | The variable with the list. |
| INDEX | index, or a list of indexes | end | The place of the element, one level of the path each. |
Returns
The element that was taken out.
Examples
% set l {a b c}
> list [lpop l] $l
c {a b}
% set l {a b c}
> list [lpop l 0] $l
a {b c}
% set l {a b c}
> list [lpop l end-1] $l
b {a c}
% set l {{a b} c}
> list [lpop l 0 0] $l
a {b c}
Errors
% set l {}
> lpop l
index "end" out of range
-errorcode TCL VALUE INDEX OUTOFRANGE
% set l {a b}
> lpop l 5
index "5" out of range
-errorcode TCL VALUE INDEX OUTOFRANGE
% unset -nocomplain nv
> lpop nv
can't read "nv": no such variable
-errorcode NONE
Differences from Tcl
- Tcl 9.0.4 names the variable
listvarin its message of a wrong count of arguments (issue 676). - A bad index and a variable with no value have
-errorcode NONE, where Tcl 9.0.4 givesTCL VALUE INDEXandTCL LOOKUP VARNAME(issue 658).
Facts
- Capability
- None.
- Tcl release
- Tcl 9.1 only.
- Since
- ztcl 1.0.0-beta.1