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

bag_retrieve(+BagHandle, -List)

Retrieve a bag's contents
BagHandle
A bag
List
A variable or list of terms

Description

This returns a list containing a copy of every term that has been entered into the bag since it was created. It should not be assumed that the list order reflects the order in which the terms were entered into the bag. Entering and retrieving terms from a bag involves copying the term each time, similar to what happens in setval/getval and record/recorded. In particular, if the term contains variables, they lose their identity and are replaced with fresh ones.

Modes and Determinism

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

    simple_findall(Goal, Solutions) :-
    	bag_create(Bag),
	(
	    call(Goal),
	    bag_enter(Bag, Goal),
	    fail
	;
	    true
	),
	bag_retrieve(Bag, Solutions),
	bag_abolish(Bag).
    

See Also

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