I paired with Daisy on the roman numerals Kata in Clojure. Daisy doesn’t have much experience with Lisp or Clojure, so this was a great opportunity for me to teach someone a language that I had recently been learning.
The first thing that I felt was important to cover is parenthesis..(there’s so many of them!). Okay while they’re important (meaning lost minutes would attest), there are four concepts that are more important.
Functions, Lists, Input, Output.
When tackling a problem, think of these four and they will lead you to a possible solution.
These four concepts aren’t in complete isolation of each other, they connect and flow between.
A rudimentary example of adding a number to a list of our favourite numbers.
(def my-favourite-number [7 11 24 50 100])
(cons 5 my-favourite-numers)
It contains a function called “cons” that takes a number and a list as an an input. Finally outputs the result.
We of course could also have a function that takes another function as an input, such as the map function which takes a functions as an input and returns a collection as it’s output.
There are many examples out. Thinking in this approach has helped me a lot in understand functional programming and clojure.