BAP Online Manuals : Library Reference : Library by Name : findall
Previous: filledpolygon
Next: flush_print_buffer

6.2.56. findall

builds a list of all arguments that cause a goal to succeed

SYNOPSIS

INCLUDE 'prolib.h'
findall(X,goal(X,args),L)

SYNTAX

findall(X,Goal,List)(i,i,o)

ARGUMENTS

void(X) (i) Some Variable contained with in Goal
void(Goal) (i) the goal to be satisfied
voidlist(Goal) (i) a list of all objects X that cause Goal to succeed

DESCRIPTION

This is a standard prolog predicate. By the use of the database, all elements X that match Goal are collected into List. X should be contained within Goal, otherwise you just get a list of variables whose listlen equals the number of solutions of Goal. As findall is using call, the Goal predicate must be exported somewhere.
The definition of findall is:

PREDICATE findall(void,void,voidlist).
findall(X,Call,_):-		% X is contained somewhere in Call
	asserta(findall_tmp(start)),
	call(Call),	b 	% call goal (bind X)
	  assertz(findall_tmp(X)),
	fail.
findall(_,_,ResList):-
	findall_collect(ResList),!.

PREDICATE findall_collect(voidlist).	% collect results of Call
findall_collect([Elem|Rest]):-
	retract(findall_tmp(Elem)),
	Elem \= start,
	findall_collect(Rest).
findall_collect([]).

LAYERS

prolog-process, client-server, object

RELATED PREDICATES

member , remove , call


BAP Online Manuals : Library Reference : Library by Name : findall
Previous: filledpolygon
Next: flush_print_buffer