Where’s My for Loop?
Clojure has no for loop and no direct mutable variables. So, how do you write all that code you are accustomed to writing with for loops?
Rather than create a hypothetical example, we decided to grab a piece of open source Java code (sort of) randomly, find a method with some for loops and variables, and port it to Clojure. We opened the Apache Commons project, which is very widely used. We selected the StringUtils class in Commons Lang, assuming that such a class would require little domain knowledge to understand. We then browsed for a method that had multiple for loops and local variables and found indexOfAny:
// From Apache Commons Lang, http://commons.apache.org/lang/