dict set
Sets the value at a path of keys in the dict of a variable.
dict set VAR KEY ?KEY ...? VALUE
Description
Sets the value at the path of keys in the dict of the variable VAR to VALUE, and gives the new dict. A new key goes at the end of its dict, and a key that exists keeps its place. A missing key on the path makes a new nested dict.
A VAR with no value starts as an empty dict. A value of VAR or on the path that is not a dict is an error, and VAR then keeps its value.
Arguments
| Argument | Type | Default | Description |
|---|---|---|---|
| VAR | variable name | required | The variable with the dict. |
| KEY | string | required | The keys of the path, at least one. |
| VALUE | any value | required | The new value. |
Returns
The new value of VAR.
Examples
% set d {a 1}
> dict set d b 2
a 1 b 2
% set d {a {b 1}}
> dict set d a c 2
a {b 1 c 2}
% unset -nocomplain e
> dict set e a b c 1
a {b {c 1}}
Errors
# The value 1 of the key a is not a dict.
% set d {a 1}
> dict set d a x y
missing value to go with key
-errorcode NONE
% dict set d a
wrong # args: should be "dict set dictVarName key ?key ...? value"
-errorcode TCL WRONGARGS
Facts
- Capability
- None.
- Tcl release
- Tcl 9.1 and 8.6.
- Since
- ztcl 1.0.0-beta.1