Day 8 — Clojure and Recursion

From the first day of class, I wondered how it would be possible to iterate through a list if data structures in this language are immutable (I had not read too much about Clojure beforehand). In Java and JavaScript, whenever we iterate by using a for or while loop, for example, we usually have a counter variable that changes value with each iteration.

One word: recursion.

At first glance, recursion (and abstract concepts) can be confusing to wrap your mind around. It helps to try to picture each method call getting placed on a stack as the lecture notes mentioned.

After going over it in class today, I thought I had a decent understanding of how recursion worked until I started working on a Clojure looping example today.

Clojure does have it’s own version of a for loop (which makes use of recursion). I still haven’t experimented with writing out a for loop in Clojure to make sure I understand how it works but perhaps this is something I can do if I have time this weekend.

After today’s assignment, I definitely have a better grasp of recursion but I know there is more work to be done if I am to have a solid understanding. I’ll be scheduling some time to read up on this topic (and how you can implement recursion in Java and JavaScript) soon.