[ Non-logical Variables, Arrays, Bags, Shelves and Stores | Reference Manual | Alphabetic Index ]

shelf_inc_and_get(+ShelfHandle, +Index, -NewValue)

Increment an integer slot within a shelf object and get the new value
ShelfHandle
A shelf handle or shelf name
Index
An integer
NewValue
A variable or integer

Description

This looks up the entry in the Index'th slot of the shelf object denoted by ShelfHandle, and if such an entry exists, and is of integer type, it is incremented by one. The new value is returned as NewValue. This predicate is a shorthand for:
	shelf_inc_and_get(ShelfHandle, Index, C1) :-
	    with_mutex(ShelfHandle, (
		shelf_get(ShelfHandle, Index, C0),
		C1 is C0 + 1,
		shelf_set(ShelfHandle, Index, C1))
	    ).
The slots are numbered from 1 to the maximum which was determined during shelf creation (but note that ECLiPSe's struct-syntax can be used to give the slots symbolic names, see struct/1).

Note: If ShelfHandle is not a handle, then it must be an atom or a compound term, and the shelf is identified by this term's toplevel functor together with the context module.

Modes and Determinism

Exceptions

(4) instantiation fault
ShelfHandle is not instantiated
(5) type error
Index is not instantiated
(5) type error
ShelfHandle is not a shelf
(5) type error
Index is not an integer
(6) out of range
Index is less than 1 or greater than the number of slots on the shelf
(6) out of range
The counter value exceeds an implementation-defined limit (at least 2^31)
(40) stale object handle
ShelfHandle refers to an already destroyed shelf

Examples

    	?- shelf_create(s(5),S), shelf_inc_and_get(S,1,New).

	S = $&(shelf,"36nzz7")
	New = 6
	Yes (0.00s cpu)
    

See Also

shelf_create / 2, shelf_create / 3, shelf_inc / 2, shelf_set / 3, shelf_get_and_dec / 3, struct / 1