I am fairly new to Prolog and I am trying to get my head around the concept of lists. An example that I am trying is:
value(a, 1).
value(b, 2).
value(a, 3).
value(a, 4).
value(c, 3).
I am trying to create a predicate which when queried find(a, List) results in: List = [1, 3, 4].
It simply goes over all the facts and adds the matching ones to the list.
I've tried something like this. but it doesn't seem right at all:
find(X, List):-
value(X, D), append([D], [], [List|Rest]), find(X, [Head|List]).
Sorry about such a basic question. Any guidance is appreciated.
Note: I intend to extend the program by making it add all the values in the list.
sumlist( List, Sum )built-in predicate. - lurker