I'm new to Prolog and I wanted to write a program that can do some computations on a cellular space. First of all, I've defined the cellular space by some facts:
board_size(3).
cell(0,0,0).
cell(0,1,0).
cell(0,2,0).
cell(1,0,0).
cell(1,1,0).
cell(1,2,0).
cell(2,0,0).
cell(2,1,0).
cell(2,2,0).
cell(X,Y,Z)
means a cell in position (X,Y)
and the value Z
.
And for finding the top cell of another cell, I've wrote this rule:
top(cell(X1,Y1,_),cell(X2,Y1,_)) :- board_size(Size), X1 is (X2-1) mod Size.
Finally I've tested my code by some queries:
1 ?- top(cell(0,0,0),cell(1,0,0)).
true.
2 ?- top(cell(0,0,0),cell(X,0,0)).
ERROR: is/2: Arguments are not sufficiently instantiated
What is the cause of this error?