tsv array
Works on a whole shared array: set, reset, get, names, and size.
tsv::array set ARRAY LIST
tsv::array reset ARRAY LIST
tsv::array get ARRAY ?PATTERN?
tsv::array names ARRAY ?PATTERN?
tsv::array size ARRAY
tsv::array isbound ARRAY
Description
The command tsv::array works on all the elements of ARRAY:
setsets the elements of LIST, a list of names and values, and keeps the other elements.resetremoves each element and then sets the elements of LIST.getgives a list of names and values, of each element or of each element whose name matches the glob PATTERN.namesgives the names of the elements, or of those that match PATTERN.sizegives the count of elements.isboundgives 0: ztcl has no storage handlers.
An array that does not exist has no elements, so get, names, and size give an empty list or 0.
Arguments
| Argument | Type | Default | Description |
|---|---|---|---|
| ARRAY | array name | required | The name of the shared array. |
| LIST | list of names and values | required | The elements to set, with an even count of words. |
| PATTERN | glob pattern | none | The names of the elements to give. |
Returns
An empty string for set and reset, else a list or a count.
Examples
% tsv::array set z {k1 v1 k2 v2}
> lsort [tsv::array names z]
k1 k2
% tsv::array set z {k1 v1 k2 v2}
> tsv::array get z k1
k1 v1
% tsv::array set z {k1 v1 k2 v2}
> tsv::array reset z {k3 v3}
> tsv::array get z
k3 v3
% tsv::array set y {k1 v1 k2 v2}
> tsv::array size y
2
% tsv::array size nope
0
Errors
% tsv::array
wrong # args: should be "tsv::array option array"
-errorcode TCL WRONGARGS
% tsv::array bogus z
bad option "bogus": must be set, reset, get, names, size, or isbound
-errorcode NONE
# ztcl has no storage handlers.
% tsv::array bind z x
bad option "bind": must be set, reset, get, names, size, or isbound
-errorcode NONE
% tsv::array set z {k1}
list must have an even number of elements
-errorcode NONE
% tsv::array size z x
wrong # args: should be "tsv::array size array"
-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