Command: INCR

Purpose: Increments by one the value of a specified array reference. This operation is atomic. If the array reference does not exist, it is created with a value of 1. The new incremented value is returned.

Note that no pre-declaration of either the array name or its subscripting structure is required. Creation of array records is totally dynamic.


Argument No Description
1 The array node to be incremented. This takes the format:
You may specify no subscripts at all, in which case the top-level node is incremented,eg:
Incrementing the first level of subscripting would look like:
Incrementing the second level of subscripting would look like:

Note that subscripts can be numeric or text. Text subscripts must be wrapped in double quote (") characters. Quoting of numeric subscripts is optional.


Single-line integer response

Server: :[new incremented value]


If test1["a","b"] does not yet exist:

Client: INCR test1["a","b"]
Server: :1

If the command is repeated:

Client: INCR test1["a","b"]
Server: :2

We can confirm the new value of test1["a","b"]:

Client: GET test1["a","b"]
Server: $1
Server: 2

For those familiar with the native language of GT.M and Caché systems, the above two examples are the equivalent of:

write $increment(^test1("a","b"))