Implementing “last” in Prolog

Question 1: Prolog systems are not always able to decide whether or not a clause will apply prior to executing it. The precise circumstances are implementation dependent. That is, you cannot rely on that decision in general. Systems do improve here from release to release. Consider as the simplest case: ?- X = 1 ; … Read more

Definition of Reflexive Transitive Closure

It’s useful, but in my opinion not yet ideal because I cannot cut duplicate paths at the point of their creation. Consider, with the complete graph K_n: n_complete(N, Es) :- numlist(1, N, Ns), phrase(pairs(Ns), Es). adjacent(Edges, X, Y) :- member(edge(X, Y), Edges). pairs([]) –> []. pairs([N|Ns]) –> edges(Ns, N), pairs(Ns). edges([], _) –> []. edges([N|Ns], … Read more