dict unset

Removes the key at the end of a path from the dict of a variable.

dict unset VAR KEY ?KEY ...?

Description

Removes the last KEY of the path from its dict in the variable VAR, and gives the new dict. A missing last key is no error: the dict stays the same. A missing key before the last one is an error.

A VAR with no value starts as an empty dict, so the result is an empty dict.

Arguments

ArgumentTypeDefaultDescription
VARvariable namerequiredThe variable with the dict.
KEYstringrequiredThe keys of the path, at least one.

Returns

The new value of VAR.

Examples

% set d {a 1 b 2}
> dict unset d a
b 2

% set d {a {x 1 y 2}}
> dict unset d a x
a {y 2}

% set d {a 1 b 2}
> dict unset d zz
a 1 b 2

Errors

% set d {a 1}
> dict unset d q r
key "q" not known in dictionary
-errorcode NONE

% dict unset d
wrong # args: should be "dict unset dictVarName key ?key ...?"
-errorcode TCL WRONGARGS

Facts

Capability
None.
Tcl release
Tcl 9.1 and 8.6.
Since
ztcl 1.0.0-beta.1

See also