How to get Y and Z in prolog, when I only know X?
For example:
test(X, Y, Z) :- X is Y + Z.
but error:
?- test(2, Y, Z).
ERROR: is/2: Arguments are not sufficiently instantiated
It's not possible, because you can choose Y
to be anything you want and them compute Z
or vice versa.
Although if you know that Y
and Z
are from some limited set (e.g. positive integers less than 5), you can do something like:
valid_number(1).
valid_number(2).
valid_number(3).
valid_number(4).
test(X, Y, Z) :- valid_number(Y), valid_number(Z), X is Y + Z.