array set
Sets elements of an array from a list of names and values.
array set ARRAYNAME LIST
Description
Sets an element for each name and value of LIST. An element that is there gets the new value, and the other elements of the array stay. When a name comes twice in LIST, the last value is the value.
When ARRAYNAME has no variable, array set makes an array. An empty LIST makes an empty array, which array exists sees. A variable with a plain value is an error.
Arguments
| Argument | Type | Default | Description |
|---|---|---|---|
| ARRAYNAME | variable name | required | The array to set. |
| LIST | list | required | A list with an even count of elements: each name followed by its value. |
Returns
An empty string.
Examples
% array set a {x 1 y 2}; array get a
x 1 y 2
% array set a {y 9 z 3}; array get a
x 1 y 9 z 3
% array set b {k 1 k 2}; array get b
k 2
% array set e {}; array exists e
1
Errors
% array set c {x 1 y}
list must have an even number of elements
-errorcode TCL WRONGARGS
% set s 1; array set s {a 1}
can't array set "s": variable isn't array
-errorcode NONE
% array set
wrong # args: should be "array set arrayName list"
-errorcode TCL WRONGARGS
Facts
- Capability
- None.
- Tcl release
- Tcl 9.1 and 8.6.
- Since
- ztcl 1.0.0-beta.1