Report: Clojure Meetup - 1
Last Tuesday we held ThoughtWorks' Australia first Clojure meetup here in Sydney. It was a lot of fun so I thought I'd share a few words about it.
The format was rather simple. First, we had a brief introduction to the language syntax by breaking down a couple of snippets and understanding how each bit worked. For instance, this is one of those snippets:
;;word count
(reduce #(if (%1 %2)
(assoc %1 %2 (inc (%1 %2)))
(assoc %1 %2 1))
{}
(clojure.string/split "Clojure 101 - this is is gonna be be great great great" #"\s"))
The cool thing here is that a simple example like this can show quite a few things about Clojure's syntax:
- Polish notation - this is really the first thing you need to get used to
- Anonymous functions
- The hash map literal and how to use it as a function
- Regular expressions
After this brief discussion about Clojure's API, we split up in pairs to solve a simple problem from Project Euler:
Add all the natural numbers below one thousand that are multiples of 3 or 5.
It's the easiest on the site so it allowed us to focus entirely on the language. My first thought was to implement it in an imperative way, but that wouldn't really teach me anything new so Kurman - the colleague I was pairing with - and I came up with this solution, which I really like:
(reduce #(if (or (= (rem %2 3) 0) (= (rem %2 5) 0)) (+ %1 %2)
%1)
0
(take 1000 (iterate inc 0)))
A simple, concise solution that demanded a functional approach. It allowed us to explore Clojure's APIs and concepts such as lazyness through the use of an infinite sequence. Fun :)
I created a github repository to host this and upcoming solutions from our group. Feel free to browse around.
Can't wait for our next meetup, when we'll hack on Overtone!