Copyright ® (1997-2013) EDMGROUP Pty Ltd - EZY Prolog Reference
back to main page
findall(<VAR_DOMAIN> ArgumentName, <PredicateCall>, <VAR_DOMAIN_LIST> ValuesList)
Assemble a list of all solutions returned by a non-deterministic predicate
ArgumentName specifies which argument in the specified predicate PredicateCall is to be collected into a list ValuesList. The irregular syntax <VAR_DOMAIN> is used to indicate a domain to which ArgumentName belongs.
PredicateCall indicates the predicate from which values will be collected.
ValuesList is an output variable that holds the list of values collected through backtracking.
The findall predicate builds the list ListVariable by backtracking into <PredicateCall> until it eventually fails. ListVariable consists of all instances of the variable ArgumentName, which must be an output argument of <PredicateCall>.
In order to findall to work, there must be a declaration of the list domain for ValuesList in the user domain declarations. That is, if ArgumentName belongs to a certain domain VAR_DOMAIN, then the program have to contain user domain declaration like the following:
VAR_DOMAIN_LIST = VAR_DOMAIN*
This list domain VAR_DOMAIN_LIST should be used to handle ValuesList variable in the program.
Sample: see findall_test.pro
/* COMPLEX TEST FOR FINDALL.
NOTE - LISTS DECLARATIONS ARE NOT COMPATIBLE WITH PDC PROLOG SYNTAX
write("Welcome to EZY Prolog\n"),
THIS DECLARATION IS NECESSARY FOR CORRECT WORK OF FINDALL
nondeterm_get_list predicate calls non-deterministic predicate list_for_test
unfortunately findall(X,list_for_test(_,X),RESULT) will not work with EZY Prolog.
Instead, additional predicate nondeterm_get_list should be declared and
called inside findall
list_for_test("List of Integers",[1,2,3,4,5]).
list_for_test("List of strings",["one","two","three","four","five"]).
list_for_test("List of elements",[element(1,"One"),element(2,"Two"),element(3,"Three"),element(4,"Four")]).
list_for_test("list with list as MEMBER",[1,2,3,element(4,"Four"),[1,2,3,4,5]]).
write("Test for findall:\n"),
/* NOTE - VARIOUS LIST IS 2D LIST */
write("List subsystem test completed\n").
EZY PROLOG. Copyright (C) 1997-2013 EDMGROUP (Australia)
Welcome to EZY Prolog
Test for findall:
List of Integers- [1,2,3,4,5]
List of strings- [one,two,three,four,five]
List of elements- [element(1,"One"),element(2,"Two"),element(3,"Three"),element(4,"Four")]
Hybrid list- [1,2,3,element(4,"Four")]
list with list as MEMBER- [1,2,3,element(4,"Four"),[1,2,3,4,5]]
List subsystem test completed
Copyright © 1997-2013 EDMGROUP (Australia)