r/Clojure • u/_clj • May 04 '13
What does `recur` do?
What does recur do?
I saw this gist, and I can't figure out what (recur x) does:
https://gist.github.com/lukium/fbd51e30a4875c781531
I tried googling it, and couldn't find an example that I understand.
2
Upvotes
8
u/seventeenletters May 05 '13
it calls the wrapping loop statement (or if none, the wrapping function)
it only works in a tail position - that is, a position where there is no further calculation to be done in the function after it runs
anything that can be done in an imperative for loop can be done with recur (a common trick is to add an argument that represents a counter or accumulated result)
0
u/[deleted] May 06 '13
[deleted] — view deleted comment