(repeat "Functions are cool")

Expectations

My primary expectation for today was to really try to get into a functional frame of mind. After yesterday's revelations with the 4Clojure problems, I wanted to try to solidify those revelations and make sure that I was comfortable with them. On a more quotidian note, I also wanted to see how many of the 4Clojure Problems I could complete.

What I learned

Today's learning material was Chapter 3 of Clojure from the Ground Up. It's all about Functions. I still remembered some of the material I studied in Brave and True so I was able to get through the chapter without much ado.

Observations:

Threader macro forms are very elegant ways of expressing transformations on data. It allows us to express code like this :

(sort (rest (reverse [4 3 6 2 7 1])))

in this form:

(-> [4 3 6 2 7 1]
		(reverse)
		(rest)
		(sort))

The expression is passed down from expression to expression as the second item in the list. This form makes it much easier to understand how the data flows and transforms.

Introspection

There are so many cool Clojure introspection features that I felt it needs its own section.

type gives you the concrete type of an object. If type isn't being useful, use supers to get all the supertypes of the object. Supertypes is the set of all types that includes the given type. We can check if a given object is a function with fn?. We can get the documentation for a function with doc. Want to find the associated metadata for an object? Simply use (meta #'obj). Confused how a function is implemented? Fret not, source is here to save the day.

That a language is so honest and forthcoming with it's fundamentals and source is amazing. Using functions like doc and source becomes second nature when you're using the REPL and it's incredibly helpful to have access to them locally.