I’m big newbie to Prolog and I’m trying to write simple generator which finds the integers below 5.
gen(0).
gen(X):- X<5
When I run the program with gen(X) it only prints X = 0 and prompts me to enter something and when I press enter the ‘?-‘ is shown again.
How to make him generate the numbers from zero to five ? I’m using SWI-Prolog. Thanks
The builtin predicate devoted to enumerate integers is between(Low,High,Num).
Using that you would write
gen(X) :- between(0,4,X).I’ve reimplemented between in this way
The interesting part of the question is to understand why the naive implementation with just an argument loops forever…