dict getdefTcl 9.1 only
Gives the value at a path of keys, or a default when a key is missing.
dict getdef DICT ?KEY ...? KEY DEFAULT
Description
Gives the value at the path of keys in DICT, as dict get does. When a key of the path is missing, it gives DEFAULT in place of an error. A value on the path that is not a dict is still an error.
dict getwithdefault is the same command. Both are in Tcl 9.1 only.
Arguments
| Argument | Type | Default | Description |
|---|---|---|---|
| DICT | dict | required | The dict. |
| KEY | string | required | The keys of the path, at least one. |
| DEFAULT | any value | required | The result when a key is missing. |
Returns
The value, or DEFAULT.
Examples
% dict getdef {a 1} b 9
9
% dict getdef {a 1} a 9
1
% dict getdef {a {b 2}} a c 0
0
% dict getdef {} a b 1
1
Errors
% dict getdef {a 1} a x 0
missing value to go with key
-errorcode NONE
% dict getdef {a 1} b
wrong # args: should be "dict getdef dictionary ?key ...? key default"
-errorcode NONE
Facts
- Capability
- None.
- Tcl release
- Tcl 9.1 only.
- Since
- ztcl 1.0.0-beta.1