For a long time, seriously , since I wrote a prologue, but I will probably do something completely different. Something like this, although I can't check it for a moment.
print_increasing_numbers(From, To):- From > To, !, write('ERROR: From > To'). print_increasing_numbers(To, To):- !, write(To). print_increasing_numbers(From, To):- write(From), nl, Next is From + 1, print_increasing_numbers(Next, To).
The key difference here is the operation ! or a cut that stops the rollback. If you do not include it, you will get a solution with the first sentence, when X is 10, but if you ask for a second solution, it will return and will correspond to the second sentence. This will lead to a much larger list of numbers than you want.
torak
source share