I'm trying to write a prolog program to demonstrate how a cut can be used to increase efficiency. I'm using the following member declaration to search through a list.
member(Element, [Element | _]).
member(Element, [_ | List]) :- member(Element, List).
The function seems to be working just fine ex:
?- member(1,[3,1,4]).
true
The issue that i'm running into is I need to be able to use member with a predeclared list. like so:
someList([3,1,4]).
?- somelist(X).
X = [3, 1, 4].
3 ?- member(1,somelist).
false.
Even though somelist is defined as [3,1,4] which works in the first test, when called this returns false. I just need to know what I'm doing wrong that ?- member(1,somelist). is returning false. Any help would be greatly appreciated.
someListis a predicate, not a function.someList(X)as you see does a query and determines that the query is satisfied by instantiatingXwith[3,1,4]. It's result is, therefore "true" (it succeeded), but it's not a function return value. Nor is the resultX = [3,1,4]a return value ofsomeListas a "function". Prolog doesn't use functions. Try:someList(L), member(1, L).which is to say,LissomeListAND1is a member ofL. - lurker