This time I really cannot understand the error: i wrote this code to get the list element at a certain position:
take_pos([], _, _) :- fail;
take_pos([H|T], 1, H).
take_pos([H|T], Pos, X) :- Pos2 is Pos - 1, take_pos(T, Pos2, X).
It never terminates; tracing it I can see that it never match the second statement. Also if i query take_pos([1,2,3], 1, 1). it match the last one.
What am I missing?
I think the problem is that you put a semicolon instead of a dot after
fail.Also consider rewriting the second rule to avoid introducing a singleton: