tsv lpop
Removes one element of a list in a shared array and gives it.
tsv::lpop ARRAY ELEMENT ?INDEX?
Description
The command tsv::lpop removes the element at INDEX, 0 by default, of the list in the element, and gives it. With end it removes the last element in amortized constant time, so tsv::lappend and tsv::lpop ... end are a stack, and tsv::lappend and tsv::lpop are a queue. An empty list, or an index past the end, gives an empty string and leaves the list as it is.
Arguments
| Argument | Type | Default | Description |
|---|---|---|---|
| ARRAY | array name | required | The name of the shared array. |
| ELEMENT | string | required | The name of the element. |
| INDEX | index | 0 | The index of the element to remove. |
Returns
The removed element, or an empty string.
Examples
% tsv::set l x {a b c}
> list [tsv::lpop l x] [tsv::get l x]
a {b c}
% tsv::set l x {a b c}
> tsv::lpop l x end
c
% tsv::set l x {}
> tsv::lpop l x
Errors
% tsv::lpop l
wrong # args: should be "tsv::lpop array key ?args?"
-errorcode TCL WRONGARGS
Facts
- Capability
thread. A new interpreter does not have it until the host turns it on.- Tcl release
- Tcl 9.1 and 8.6.
- Since
- ztcl 1.0.0-beta.1