After loading the following program using SWI-Prolog and entering queries such as
cells([o,x,o,x,o], A).
or
cells(A, [o,x,o,x,o]).
the first result seems to always be correct, but after submitting semicolon to look for more results (and I don't know if there should be additional results in either case), I get a PROLOG SYSTEM ERROR mentioning garbage collection and an Out of global stack error respectively.
regla(o,o,o,o).
regla(x,o,o,x).
regla(o,x,o,o).
regla(o,o,x,x).
regla(x,o,x,x).
regla(x,x,o,x).
regla(o,x,x,x).
regla(x,x,x,o).
cells([X | XS], [Y | YS]) :-
X = o,
Y = o,
length([X | XS], LX),
LX >= 3,
length([Y | YS], LY),
LY is LX + 2,
append([o, o], [X | XS], W),
append(W, [o, o], Z),
cellsR(Z, [Y | YS]).
cellsR(_, []).
cellsR([A, B, C | R], [H | T]) :-
regla(A, B, C, H),
cellsR([B, C | R], T).
I'm assuming that the errors have to do with the way I handle recursion, so maybe someone can have a look at the code and tell me where I'm going wrong.