Reputation: 706
Consider the following case:
card([a,b,c,d,e]).
How can I access this list, in a new nth0/3 function without redefining the list elements in it?
Example:
?- nth0(2, card, X).
X = c
I tried looking online but all of them had the list defined in the nth0 itself.
So my question is, is it possible to do something like this? If so, how?
Upvotes: 1
Views: 374
Reputation: 22803
The way you would obtain the value of card/1
would be to supply it to a query, like this:
?- card(Card), nth0(2, Card, X).
Since the capitals are variables, this is going to be about the same as if you did something like this:
?- Card = [_,_,X,_,_].
I fear you are hoping to see some state between queries, but Prolog doesn’t do that. In your next query, card/1
will again just be a list of five unknown elements. For this reason, your card/1
definition smells fishy to me. What are you trying to do?
Upvotes: 1