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

# bag_count(+BagHandle, -Count)

Get the number of entries in a bag

BagHandle
  A bag
Count
  A variable or integer

## Description

This returns an integer corresponding to the number of entries currently in the bag. A fresh or erased bag has zero entries.

### Modes and Determinism

- bag_count(+, -) is det

### Exceptions

(4) instantiation fault
  BagHandle is not instantiated
(5) type error
  BagHandle is not a bag
(40) stale object handle
  BagHandle refers to an already destroyed bag

## Examples

        ?- bag_create(B), bag_count(B, N0), bag_enter(B, one), bag_count(B, N1).
        N0 = 0
        B = $&(bag,"371bnb")
        N1 = 1
        Yes (0.00s cpu)

## See Also

bag_create / 1, bag_enter / 2, bag_count / 2, bag_erase / 1, bag_abolish / 1, bag_retrieve / 2, bag_dissolve / 2