I have to make a function in Scheme (R5RS) that works as follow : (power-close-to b n) And it has to return a integer that I call "e" that is : b^e > n With b, e and n integers.
So if we do : (power-close-to 2 10) It has to return 4, because 4 is the first integer for which b^e > n I've made this function in an iterative way but I have to make it in an recursive form. So this is my code:
(define e 0)
(define (power-close-to b n)
(for ((e (< (expt b e) n))
(+ e 1))
e))
But when I try it, Scheme gives following error : "for: undefined;" So it seems my Scheme don't know the procedure "for", but I saw it in multiple Scheme codes on the internet, so I don't understand why in my case he says he don't know "for".
Thanks for your help!
EDIT : I tried making it recursive, this is how i did it, but i think it still is iterative, and i really don't have any idea how i could make it recursive.
(define e 0)
(define (power-close-to b n)
(if (< (expt b e) n)
(and (set! e (+ e 1)) (power-close-to b n))
e))
I also tried this, but when i try it, it never prints anything and never ends (but this is recursive (i think))
(define e 0)
(define (power-close-to b n)
(if (< (expt b e) n)
(* b (power-close-to b n))
e))
fordoesn't exist in your interpreter - Óscar López