[ Non-logical Variables, Arrays, Bags, Shelves and Stores | The ECLiPSe Built-In Predicates | Reference Manual | Alphabetic Index ]
store_inc(+StoreHandle, ++Key)
Increment an integral entry within a store object
- StoreHandle
- A store handle or store name
- Key
- A ground term
Description
This looks up an entry under a given key in a given store object, and
if such an entry exists, and is of integer type, it is incremented by
one. If no entry exists, an entry with integer value 1 is created.
This predicate is a shorthand for:
store_inc(Handle, Key) :-
( store_get(Handle, Key, C0) ->
C1 is C0 + 1,
store_set(Handle, Key, C1)
;
store_set(Handle, Key, 1)
).
Note: If StoreHandle is not a handle, then it must be an atom or a
compound term, and the store is identified by this term's toplevel
functor together with the context module.
Fail Conditions
None
Resatisfiable
No
Exceptions
- (4) instantiation fault
- StoreHandle is uninstantiated
- (4) instantiation fault
- Key is not a ground term
- (5) type error
- StoreHandle is neither atom nor compound term nor store handle
- (45) record does not exist
- StoreHandle is not the name of a store
Examples
?- store_create(Handle),
store_set(Handle, count, 7),
store_inc(Handle, count),
store_get(Handle, count, N).
Handle = 'STORE'(16'00334e20)
N1 = 8
Yes (0.00s cpu)
?- store_create(Handle),
store_inc(Handle, foo),
store_get(Handle, foo, N).
Handle = 'STORE'(16'00334e20)
N = 1
Yes (0.00s cpu)
See Also
store / 1, local / 1, store_set / 3, store_get / 3, store_delete / 2, store_contains / 2, stored_keys / 2, stored_keys_and_values / 2, store_create / 1, store_count / 2