4 ms·
You just have to indent them the same way you'd indent curly braces. The harder part about lisp is actually recursion. Surprisingly, there aren't a lot of prog
by didip 9y ago
You just have to indent them the same way you'd indent curly braces.
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)
- ZenoArrow 9y ago>"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.
- xfer 9y agoNot 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.
- Sharlin 9y agoIn 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.
- hellofunk 9y agoI would say nearly all my loops are either map or reduce. That's it.