My morning started off similar to yesterday. Woke up 6am, had breakfast and coffee, except instead of working on problems on 4Clojure I started working on Clojure Koans. Today was a little more taxing on the brain than yesterday. The further into the Clojure Koans I got, the longer they took me to grasp the key concepts. The concepts I struggled with today were refs, defrecords vs deftypes, java-interop, group-by, and metas.

Refs: A ref is a reference type in Clojure that allows you to manage mutable state. It ensures that changes to the state are coordinated and can be done in a transactional way, meaning multiple updates can be made atomically. Updates to a ref must be made inside of a dosync block. You can change the value of a ref with either “alter” (updates it based on its current value), “commute” (used for commutative updates where the order of the changes doesn’t matter), or “ref-set” (directly sets/replaces the old value for a new value).

Defrecords vs Deftypes: A defrecord is similar to a map, except it is optimized for cases where you have a fixed set of keys and want to ensure better performance and type safety. Defrecords can have elements called upon like a map using keywords. Defrecords are also immutable by default. Deftypes on the other hand can have both mutable and immutable fields. They also can’t have their elements called upon by keywords.

Java Interoperability: Java Interopability is the feature of clojure where you can integrate and call upon java classes, methods, and libraries in your clojure code. (clojure does run on the Java Virtual Machine after all). Honestly, the only reason I struggled with this section was the fact that I’ve never programmed in Java, so I had to look up every class and method in this section. It wasn’t a hard concept over all. In fact it actually was more seamless than I had imagined. I can’t wait to get more familiar with the Java ecosystem to start pulling from existing libraries.

Group-by: Group-by is a function that takes a function as its first argument and a collection as a second argument. It then maps through the collection and groups the elements according to the value returned by the function. This one really isn’t a super complicated concept, but I think I was studying it during the point in the day where my attention span does not want to cooperate with my intentions.

Metas: Meta data is a way to add information to symbols, collections, and functions without altering the object’s value. It can be useful in adding documentation and type hints to these objects. The syntax of it is what confuses me the most. I plan on going over this concept again when I wake up in the morning.

All together today, I feel like I’ve nearly doubled my knowledge of Clojure today. Even though I’ve barely scratched the surface of what I can do with this language, I feel as if I’ve atleast taken my first 10 steps on a million mile journey.

I plan on finishing off my day by watching Uncle Bob’s video on Functions in the fundamentals series before I go to bed, so I can wake up refreshed and ready for day three of my apprenticeship!