CapelliC's answer is correct, and he discusses why you should use the built-in nth/3
or however it is called (nth1/3
is actually not ISO, and not available in some implementations, like GNU-Prolog). I just want to add some clarification:
Your first issue here is that to ask a question, "does the Nth element of a list have a certain value", you need two arguments already: N and Value. Also, is
is a predicate for evaluating arithmetic expressions and cannot be used for your purpose.
As for the query(data1)
, you need some form of meta-calling....
In summary:
% query(Fact, N, Value) is true
% when the Nth element of the list argument of Fact is Value
query(Fact, N, Value) :-
call(Fact, List),
nth(N, List, Value).
and it can be called like this:
?- query(data1, 3, 15).
to query all data1
facts that have one argument, a list.
Here nth
should be defined as:
nth(N, List, Value) is true when Value is the Nth element of List
but you should really rather use the built-in available in the implementation you are using.