Re:Why I'm Productive in Clojure (2013)
by ZenoArrow on Sunday October 22, 2017 @04:30AM
(#15525759)
>"The harder part about lisp is actually recursion. Surprisingly, there aren't a lot of programmers who can follow recursion naturally."
All examples of recursion I've ever seen in Lisp follow a similar structure...
* First section checks if recursion is finished. If so, return final result (or final element of full result if returning a list).
* Second section performs an action or two on the inputs.
* Third section calls the function again with revised inputs.
In many ways it's just a do while loop with different syntax.
Not true; loops exist (as a macro) because recursive functions(that naturally correspond to loops and iterations) are harder to read because they hide the logic of termination conditions. Fortunately we are using a powerful language, that lets us transform natural loop syntax to a recursive function.
In my experience you rarely need recursion in Clojure, to the point that it's unidiomatic to use it. For 95% of your looping needs you use combinators, and for the rest there are the loop macros.
The harder part about lisp is actually recursion. Surprisingly, there aren't a lot of programmers who can follow recursion naturally.
(loop exists in lisp but recursion seems to be the common idiom)