dict incr

Adds an integer to the value of a key in the dict of a variable.

dict incr VAR KEY ?INCREMENT?

Description

Adds INCREMENT to the integer value of KEY in the dict of the variable VAR, and gives the new dict. INCREMENT is 1 by default, and it can be negative or in any integer form, such as 0x10. A missing key starts at 0, and a VAR with no value starts as an empty dict. The sum has no size limit: it does not wrap at 64 bits.

The value of the key and INCREMENT must be integers.

Arguments

ArgumentTypeDefaultDescription
VARvariable namerequiredThe variable with the dict.
KEYstringrequiredThe key of the integer.
INCREMENTinteger1The amount to add.

Returns

The new value of VAR.

Examples

% set d {n 1}
> dict incr d n
n 2

% set d {n 1}
> dict incr d n -2
n -1

% set d {}
> dict incr d m 0x10
m 16

% set d {n 1}
> dict incr d n 9223372036854775807
n 9223372036854775808

Errors

% set d {n x}
> dict incr d n
expected integer but got "x"
-errorcode NONE

% set d {n 1}
> dict incr d n 1.5
expected integer but got "1.5"
-errorcode NONE

Differences from Tcl

Facts

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

See also