How do I define this predicate so that it doesn't run forever

Viewed 70

I need to define a predicate such that:

?- X = succ(X), nu(X).
false.

How do I do it? It just seems like it won't return anything and just run forever.

1 Answers

You can try like this:

nu(0).
nu(S) :-
    acyclic_term(S),
    S = succ(X),
    nu(X).

The acyclic_term/1 call is necessary to fail in the first query.

Related