
shelf_dec(+ShelfHandle, +Index)

   Decrement an integer slot within a shelf object but fail if is zero

Arguments
   ShelfHandle         A shelf handle or shelf name
   Index               An integer

Type
   Non-logical Variables, Arrays, Bags, Shelves and Stores

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 decremented by one.  If the old value is already zero
	(or less), the predicate fails and the shelf remains unchanged.
	This predicate is a shorthand for:

	shelf_dec(ShelfHandle, Index) :-
	    shelf_get(ShelfHandle, Index, C0),
	    C0 > 0,
	    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
   shelf_dec(+, +) is semidet

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

Fail Conditions
   Fails if decrementing the value would result in a negative number

Exceptions
     4 --- ShelfHandle is not instantiated
     5 --- Index is not instantiated
     5 --- ShelfHandle is not a shelf
     5 --- Index is not an integer
     6 --- Index is less than 1 or greater than the number of slots on the shelf
     6 --- The old counter value exceeds an implementation-defined limit (at least 2^31)
    40 --- ShelfHandle refers to an already destroyed shelf

Examples
   
    :- local shelf(backtrack_limit, count(100)).

    nat(0).
    nat(N) :-
	shelf_dec(backtrack_limit, 1),   % fail when limit reached
	nat(N0),
    	N is N0+1.

    ?- shelf_set(backtrack_limit, 1, 5),
       findall(X, nat(X), L).

    X = X
    L = [0, 1, 2, 3, 4, 5]
    Yes (0.00s cpu)
    

See Also
   shelf_create / 2, shelf_create / 3, shelf_inc / 2, shelf_set / 3, shelf_abolish / 1, struct / 1
