Command: DECR

Purpose: Decrements 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 decremented 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 decremented. This takes the format:
You may specify no subscripts at all, in which case the top-level node is decremented,eg:
Decrementing the first level of subscripting would look like:
Decrementing 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 decremented value]


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

Client: DECR test1["a","b"]
Server: :-1

If the command is repeated:

Client: DECR test1["a","b"]
Server: :-2

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

Client: GET test1["a","b"]
Server: $2
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"),-1)