I am working on a problem from SICP. I am not sure why this function results in an infinite while loop. Can someone please shed some light on this? I am sure there might be better ways to write this loop, but I am new to functional programming and still trying to wrap my head around writing loops like this.
(define (search-for-primes a b)
(if (> a b) (display " Done"))
((timed-prime-test a) (search-for-primes (+ a 1) b)))
The program keeps printing "Done" for this input: (search-for-primes 2 10), which makes no sense. 'timed-prime-test' is a function which checks whether an input is a prime no. or not. Here's what I thinking: the program keeps calling itself until a = 11, at which point it would quit. However, even for the first 9 iterations (a=2 to a=10), I see no output from 'timed-prime-test' function and this indicates to me that the control is not even reaching the 2nd line, but then how is the function call happening infinite times?
Edit: I was looking at the syntax of 'if' in the book again and I noticed two things: a) 'alternative' is my code is outside the if block which is wrong. I fixed this but the program output for a = 10. b) A footnote says that it should only have single expressions. Does this behavior of my program has to do with b)? If yes, how does the program execution happen in this case?