So I'm having trouble trying to obtain a single element from a list using Prolog without using recursion, only relying on loops, such as foreach, foreachelem, etc....
So I have a list Xs = [1,2,3], and I want to obtain each element individually. The best I've come up so far is this...
sumOfList(Xs, Max) :-
( foreach(List, Xs), count(I, 1, _), param(Xs)
do
( foreach(List2, Xs), count(J, 2, _), param(Xs, I, List)
do
( List =< List2
-> Max is List2;
Max is List1
)
)
).
This is the best I've got so far... So I'm wondering, how do I create some kind of placeholder for Max that can be used for the final calculation?