Next: findall
Up: No Title
Previous: No Title
- Backtracking used for obtaining multiple solutions
- Results obtained one by one which meet the requirements of a single goal
- Each time we generate a new solution - we need to overwrite the
previous one
Variable binding to one solution - then another - and so on until
all solutions have been obtained
- However, sometimes prefer to have all the generated objects available
together - into a List
- This is achieved in Prolog, using bagof and setof
- Some Prolog implementations provide findall
miles(sketches_of_spain).
miles(aura).
miles(do_bop).
miles(tutu).
miles(amandala).
miles(a_kind_of_blue).
jones(back_on_the_block).
jones(right_thing).
jones(swing).
Q: miles(X)
A: X = sketches_of_spain
Then need to explicitly ask for more solutions to the query -
in which case it fails backtracking result and repeats the query
starting from the point where the last call was satisfied.
A : X = aura
However, if we issue the query :
Q: findall(X,miles(X),L)
A: X = _34 ; L = [ sketches_of_spain, aura,
do_bop, tutu, amandala, a_kind_of_blue ]
Omer F Rana
Thu Feb 20 20:05:17 GMT 1997