[ Non-logical Variables, Arrays, Bags, Shelves and Stores | 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.

Modes and Determinism

Modules

This predicate is sensitive to its module context (tool predicate, see @/2).

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) named object 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,"17h3")
    N1 = 8
    Yes (0.00s cpu)

    ?- store_create(Handle),
       store_inc(Handle, foo),
       store_get(Handle, foo, N).
    Handle = $&(store,"17h3")
    N = 1
    Yes (0.00s cpu)
    

See Also

store / 1, store_create / 1, store_contains / 2, store_count / 2, store_get / 3, store_insert / 3, store_set / 3, store_test_and_set / 4, store_update / 4