Infinite loop while generating a sequence of integers
Author |
Message |
Marcel Bodewit #1 / 4
|
 Infinite loop while generating a sequence of integers
Hi, I've got a function that generates the sequence of integers from A to B. For example: genint(2,5,Q). results in Q = [2, 3, 4, 5]. But if I enter ";", it should result in "no". But instead, it makes an infinite loop. How can I avoid this loop?
|
Sat, 08 May 2004 23:04:15 GMT |
|
 |
Leconte Jean Miche #2 / 4
|
 Infinite loop while generating a sequence of integers
Quote:
> Hi, > I've got a function that generates the sequence of integers from A to B. > For example: genint(2,5,Q). results in Q = [2, 3, 4, 5]. > But if I enter ";", it should result in "no". But instead, it makes an > infinite loop. How can I avoid this loop?
try : genint(X,Y,L):-Y < X,!, genint(Y,X,L). genint(X,X,[X]):-!. genint(X,Y,[X|L]):- V is X +1 , genint(V,Y,L). Jean Michel LECONTE
|
Sun, 09 May 2004 01:55:31 GMT |
|
 |
Bart Demoe #3 / 4
|
 Infinite loop while generating a sequence of integers
Quote:
> Hi, > I've got a function that generates the sequence of integers from A to B. > For example: genint(2,5,Q). results in Q = [2, 3, 4, 5]. > But if I enter ";", it should result in "no". But instead, it makes an > infinite loop. How can I avoid this loop?
If it hurts when you bang your head against the wall, stop banging your head against the wall. Now, would you be so kind as to send in your program so that we can see what "this loop" is ? Bart Demoen
|
Sun, 09 May 2004 00:57:51 GMT |
|
 |
Marcel Bodewit #4 / 4
|
 Infinite loop while generating a sequence of integers
thanks! The cut-symbol ('!') was the solution....
Quote:
> > Hi, > > I've got a function that generates the sequence of integers from A to B. > > For example: genint(2,5,Q). results in Q = [2, 3, 4, 5]. > > But if I enter ";", it should result in "no". But instead, it makes an > > infinite loop. How can I avoid this loop? > try : > genint(X,Y,L):-Y < X,!, genint(Y,X,L). > genint(X,X,[X]):-!. > genint(X,Y,[X|L]):- V is X +1 , genint(V,Y,L). > Jean Michel LECONTE
|
Sun, 09 May 2004 05:25:08 GMT |
|
|
|