Putting all results of a query in a list in Prolog -


i'd know how make predicate puts results obtained query (so result , press semicolon until false) in list.

for example if write foo(x,[1,2,3]). in prolog listener, let's result is

x=[11]; x=[22]; false. 

i results in list, following happen.

?-another_foo(x,[1,2,3]). x=[[11],[22]]. 

another_foo somehow use foo create list results foo. don't know how.

use built-in predicate findall/3:

?-findall(x0, foo(x0, [1,2,3]), x). x = [[11], [22]]. 

you can define another_foo/2:

another_foo(x, input) :-   findall(x0, foo(x0, input), x). 

Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -