A year (or maybe more) ago, I started toying with emacs and soon had to tweak its configuration file, which is actually a program written in elisp, a variant of the lisps family.
I had no former experience with anything like lisp before, and anytime I touched the .emacs file, a pile of weird error messages would show up when starting emacs. So I thought it might be a good idea to learn the lisp’s syntax so I’d at least know what was that unbalanced quote I kept seeing in .emacs snippets in the internets.
With time, I started appreciating more and more lisp’s minimalistic syntax, and here I am now, spending more and more time toying with Clojure, a modern Lisp variant that runs on the JVM (my platform of choice, being a Java developer for a couple of years already).
Before that, I learned me some Scala, and to help myself get rid of my imperative programmer reflexes (for loops, variables, etc.), I started coding the solutions for the excellent s99 problems using Scala. It was a joyful although painful experience: Painful because my mind would find the imperative solution first, but I had to refrain from using it while knowing that Scala’s constructs would let me do it, and rather keep reminding myself that the functional solution would have no variables. Joyful because I had to challenge my thought process to not pick the familiar path and tackle problems differently.
Now that I’m trying to learn Clojure, I figured I’d do the same and solve the s99 problems using Clojure. The problems are generic enough and not tied to any specific language.
In the following you’ll find the first 3 problems and their (hopefully) explained solutions.
Disclaimer: I’m still in my baby steps with Clojure and did the best I could with the little I know so far. I would be glad to hear the other clojurists opinions on my approach and any constructive criticism.
Read more of this post