'Prolog: succ(X,Y) evade arguments are not sufficiently instantiated error?
I have a program looking like this minimal example:
test(1, N, M) :-
succ(N, NN),
random(1, 4, X),
test(X, NN, M).
test(2, N, M) :-
succ(MM, M),
random(1, 4, X),
test(X,N, MM).
test(3, N, M) :-
N=M.
My aim now is to calculate the variable M, such that the call:
test(1,1,M).
makes sense in this context. I know in this example I could easily replace
test(2, N, M) :-
succ(MM, M),
random(1, 4, X),
test(X,N, MM).
by
test(2, N, M) :-
succ(N, NN),
random(1, 4, X),
test(X,NN, M).
to solve the problem. But in my more complicated program this is not possible. And I don't have the clue to replace this example by another one to exclude this possibility.
So my question:
is their a possibility to generalize the predicate succ predicate in such a way, the function test would be possible. Means succ(X,Y) would give Y = X + 1 and Y is calculated recursively after N = M is called in test(3, N, M).
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
