I have written the following code snippet in scheme,
(define (test-for-prime number divisor)
(cond (prime? number) (number)
(else (let ((next-divisor) (find-next-divisor number (+ 1 divisor)))
(test-for-prime (/ number next-divisor) (next-divisor))))))
However, I get the following error
let: bad syntax (not an identifier and expression for a binding) in: (next-divisor)
How do I rectify it?
Try this version, it fixes all the syntax errors:
You have lots of misplaced parenthesis. Some are missing, some are mistaken … I’d suggest you take a good read at a Scheme tutorial and play around writing some basic procedures to get the hang of it, in particular here is the documentation and correct structure for a
letspecial form:Also it’s a good idea to use an IDE/editor which highlights this kind of problems and helps you indent the code properly. In particular, be aware that a variable must not be surrounded in parenthesis, when you write this:
(x)Scheme assumes thatxis a procedure and that you’re calling it.