?- import nth0/3, nth/3 from lists.
?- nth(2, [1,2,3], Z).
Z = 2
?- nth0(2, [1,2,3], Z).
Z = 2 % Oops -- result should be 3.
(The result is correct when the first arg is unininstantiated.)
A fix:
nth0(N, L, X) :-
integer(N), !,
N >= 0,
N1 is N + 1,
'$nth1'(N1, L, X).