beetlebug▾
/

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:

An array that does not exist has no elements, so get, names, and size give an empty list or 0.

Arguments

ArgumentTypeDefaultDescription
ARRAYarray namerequiredThe name of the shared array.
LISTlist of names and valuesrequiredThe elements to set, with an even count of words.
PATTERNglob patternnoneThe 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

See also