The following code is giving me a fatal local stack overflow error (after all solutions are found, instead of "no"), and I don't understand why. I'm pretty sure that it has something to do with the range predicate, since if I replace it with a list, I don't have the issue, but I don't understand how it's causing an overflow.
nqueens(N,X) :-
pattern(N,X),range(N,Yrange),legal(Yrange,X).
nocheck(_, []).
nocheck(X/Y, [X1/Y1 | Rest]) :-
Y =\= Y1,
abs(Y1-Y) =\= abs(X1-X),
nocheck(X/Y, Rest).
legal(_,[]).
legal(Yrange,[X/Y | Rest]) :-
legal(Yrange,Rest),
member(Y,Yrange),
nocheck(X/Y, Rest).
pattern(1,[1/_]).
pattern(N,[N/_|T]) :- N1 is N-1,pattern(N1,T).
range(1,[1]).
range(N,[N|T]) :- N1 is N-1,range(N1,T).
tracecommand, followed by your actual query, to step through what is actually happening. You should add what you're actually trying to achieve with your program to the question, as Prolog is goal-oriented and without specifying what you want to achieve, we can only guess. - G_VN > 1condition in the second clause of yourrange/2predicate. - lurker