Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

getting elements into a list

Status
Not open for further replies.

djgloom

Technical User
Mar 20, 2007
2
0
0
DE
Hello!

Could you help me with an advise: how to get elements into a list:

el(a).
el(b).
el(c).
...

so, that prolog answers:

? - list(L).
L = [a, b, c, ...]
No

Thank you in advance!
 
You can achieve this using the inbuilt setof predicate like this:

el(a).
el(b).
el(c).

list(L):-
setof(X, el(X), L).
 
Thanks a lot!
There is also equivalent builtin predicate findall(X, el(X), List)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top