I'm trying to get a Fibonacci numbers using loop-recur construction:
(defn fibo-looprecur [x]
(loop [current 0
next 1
result x]
(if (= x 0) current (recur next (+' current next) (dec result))))
)
When I run it, it works OK with 0, but when I put 1 to fibo-looprecur, it goes to an infinite loop. What could cause that behaviour?
current,next, andresulttake on new values. More importantly,xwill always have its same original value --- if you call the function withxset to1, it will always be1and never0. Hence the loop will never exit.(dec result)change x to 0?result. So check that binding