call_nth(G_0, Nth)
is true iff call(G_0)
is
true and N being the number of re-executions
of call(G_0)
, Nth
unifies with the integer N+1.
Procedurally, call_nth(G_0, Nth)
is executed as
follows:
Nth
is an integer smaller or equal N,
the goal fails,
Nth
, the goal fails,
call(G_0)
,
Nth
with counter N,
call_nth(G_0, Nth)
is re-executable. On backtracking,
continue at p.p.9.1 g.
call_nth(?term, ?integer)
G_0
is a variable and Nth
is not zeroinstantiation_error.
G_0
is neither a variable nor a callable termNth
is not zerotype_error(callable, G_0).
Nth
is neither a variable nor an integertype_error(integer, Nth).
Nth
is an integer less than zerodomain_error(not_less_than_zero, Nth).
bounded
is true
and
at stepmax_integer
evaluation_error(int_overflow).
representation_error(max_integer).
?- call_nth(true, Nth). Nth = 1. ?- call_nth(false, Nth). false. ?- call_nth(repeat, Nth). Nth = 1 ; Nth = 2 ; Nth = 3 ; Nth = 4 ; Nth = 5 ; ... . ?- call_nth(( N = 1 ; N = 2 ), Nth). N = 1, Nth = 1 ; N = 2, Nth = 2. ?- call_nth(true, non_integer). type_error(integer,non_integer). ?- call_nth(true, 1.0). type_error(integer,1.0). ?- call_nth(true, 0). false. ?- call_nth(repeat, 0). false. ?- call_nth(repeat, -1). domain_error(not_less_than_zero,-1). ?- call_nth(length(L,N), 3). L = [_A,_B], N = 2. ?- call_nth(inex, 0). false. % thus not existence_error(procedure,inex/0) ?- call_nth(inex, 0). existence_error(procedure,_), unexpected. ?- call_nth(1, 0). false. ?- call_nth(V, 0). false. ?- call_nth(N = 1, N). N = 1. ?- call_nth(N = -1, N). false. ?- call_nth(repeat,1+1). type_error(integer,1+1).