Into The World of Clojure

The majority of my time as a professional software developer is spent programming in JavaScript (more specifically, Node.js) and C# (again, more specifically - .NET MVC). When I'm not knee-deep in this mixture, I like to venture into the world of functional programming. And perhaps to discover something new, something completely out of the ordinary. For me, that was Clojure.

My initial investigations into Clojure left me sort of, stumped. The difference even in semantics alone is enough to completely put you off investing your precious spare time into attempting to understand it! What on earth is reverse polish notation? And why is literally everything wrapped in parentheses? Hopefully, this article will help demystify this obscure yet purely elegant language.

As I previously mentioned, almost everything in Clojure will seem downright bewildering to the majority of software developers. With its Lisp-uresque dialect, it truly allows for a more expressive experience, which, with enough time to master, will provide joy to the majority of programmers who are truly passionate about the quality of their code.

To start off, everything in Clojure is evaluated in a uniform structure (or rather, as Forms). That is, it recognises expressions in both literal (i.e defining a map or a vector) and operational formats. For example:



A few things to observe:

  1. "Vectors" are the common term for what most developers will know as Arrays or Lists. All data structures in Clojure are also immutable, in that once defined, their state cannot be changed. This is a huge plus to functional programming!
  2. Notice the ordering of operations in the first statement? This is order known as Reverse Polish Notation (see http://www-stone.ch.cam.ac.uk/documentation/rrf/rpn.html). This basically means that operators (such as `+ - / *`) all appear before a sequential list of operands.
  3. Basic types can be passed literally, but also defined by their individual types; to name a few - Number, String, Map or Set.
  4. Common operational commands such as if statements, loops, and variable declaration are pretty self-explanatory if you look at other languages (such as the usage of let) note: the loop above is actually a Clojure Macro (and statements such as if are called special forms).
  5. Creating variables (such as using def) is commonly known as assigning variables in other languages - in Clojure, this is known as binding (see point 1 on immutable values).

Of course, the examples above do not give the language justice in any sense; Clojure has a large variety of native simple types and intuitive data structures.

This is all great and fine for a REPL, but what about actual programs? What do we do when we have a particular piece of functionality in mind? Functions that's what!

In the operational examples above I also forgot to mention one thing: and that was the calling of the native Clojure function; first. Clojure has a large number of native functions, but what about defining our own functions? Here's a good basic example of defining functions:

As the comments in the example above state, we're seeing a very simple function being defined, passed parameters, and then returning a result. You can also declare anonymous functions (much like JavaScript for example), using the following notation: “(fn [params] body)” (so just swap defn for fn). Functions in Clojure are also similar to javascript, in that they can, in fact, return other functions and be passed functions as parameters (first-class functions).

Clojure as a language provides a unique way to write complex applications. It provides an elegant, powerful syntax which makes complex applications seem trivial to write. There is a LOT more that can be said about Clojure, but to get started in writing Clojure head to Try Clojure  to start a REPL, and writing awesome stuff! If you're like me and like to get straight into reading about Clojure, I'd highly recommend Clojure for the brave and true (http://www.braveclojure.com/); a fantastic read to really get to grips (and it's also free to read online).


Who Are Ronald James?

We are a leading niche digital & tech recruitment specialist for the North East of England. We Specialise in the acquisition of high-performing technology talent across a variety of IT sectors including Digital & Technology Software Development.

Our ultimate goal is to make a positive impact on every client and candidate we serve - from the initial call and introduction, right up to the final delivery, we want our clients and candidates to feel they have had a beneficial and productive experience.

Contact our Team

If you’re looking to start your journey in sourcing talent or find your dream job, you’ll need a passionate, motivated team of experts to guide you. Check out our Jobs page for open vacancies. If interested, contact us or call 0191 620 0123 for a quick chat with our team.

Let's be Friends!

Follow us on our blog, Facebook, LinkedIn, Twitter or Instagram to follow industry news, events, success stories and new blogs releases.


Back to Blog

</Follow Us>