My thoughts after using Clojure for about a month

speckx1 pts0 comments

My thoughts after using Clojure for about a month | acdw.netI am now generating this website with Clojure (yes, right after rewriting it in GNU Make and shell; I have a problem, ok?).<br>In a personal tradition, I used writing a static site generator as the project to play with and learn Clojure as a new language.<br>While I&rsquo;ve long scoffed at Clojure for its copious syntax (three types of brackets!?), it turns out to be pretty ergonomic and powerful.<br>Here are my impressions after playing around with Clojure for about a month.

Things I like

More cohesive than Common Lisp

Common Lisp is so called because it&rsquo;s a compromise among roughly all the extant lisps when it was written in the early 80s.<br>As such, it&rsquo;s a weird mashup of programming paradigms and name schemes.<br>Instead of map-ing a function over a list, for example, you mapcar it.<br>Instead of filter, you write remove-if-not, with all the confusion of a double-negative.<br>Overall, Common Lisp has a strong feeling of being designed by committee, whch makes sense, because it was.

Because Clojure is newer and the brainchild of one person, it&rsquo;s more cohesive as a language.<br>The seq abstraction, for example, means I usually don&rsquo;t have to worry about what kind of sequence I&rsquo;m dealing with.<br>Instead of having to remember aref for arrays and nth for lists, I just use nth for everything.<br>It also makes mapping easier: instead of having to remember

;; This is real syntax!<br>(loop for k being the hash-keys<br>using (hash-value v) of hash-table<br>...)

;; OK, you could also use<br>(maphash (lambda (k v) ...) hash-table)

I can simply call (map (fn [[k v] ...]) hash-table) and be done with it.<br>And remember, map works with any collection.

It&rsquo;s the same with equality: instead of having to remember the fine distinctions between eq, eql, equal, equalp, and more that are type-specific, I can just call = (or == if comparing numerical values, or identical? to see if values are identical). To be fair, there are caveats, but I haven&rsquo;t run into them in a month.<br>I had to learn the different equality forms immediately to get going with Lisp.

More &ldquo;batteries included&rdquo; than Scheme

Scheme was also built by committee, but you could argue it&rsquo;s even more cohesive than Clojure.<br>However, it&rsquo;s &ldquo;cohesive&rdquo; in the way that a bicycle is cohesive: it includes very little in the way of ergonomics, paring down the language to its barest bones.<br>Indeed, the introduction to every revision of the Scheme Report begins:

Programming languages should be designed not by piling feature on top of feature, but by removing the weaknesses and restrictions that make additional features appear necessary.

Schemers often boast that the R5RS spec fits within 50 pages, which is impressive, but basic functionality like error handling, file handling, and even hash-maps are missing from the core language.<br>While R6RS added plenty of functionality, it also caused a huge rift in the community that R7RS is trying to heal, but it&rsquo;s slow going.

Scheme is like this beautiful jewel, an implementation of a pure programming ideal.<br>Clojure, on the other hand, is pragmatic: it has a large standard library and is hosted on the JVM, so there&rsquo;s probably a library for whatever domain you&rsquo;re working in.<br>Especially as a hobbyist programmer, I appreciate the ecosystem.

Ergonomic data structures

One of the things that first drew me to Lisp is that it&rsquo;s an &ldquo;everything-is-a&rdquo; language.<br>You know, like

Lua : everything is a table

Tcl : everything is a string

Lisp : everything is a list

I just love languages where there&rsquo;s one Big Idea and it&rsquo;s taken all the way to the bank.

However, in &ldquo;real life,&rdquo; everything is not a list.<br>There are, for example, vectors (random-access lists), or dictionaries (association lists).<br>Non-Clojure lisps have these, but Clojure makes them first-class and ergonomic.<br>This is the thing about Clojure that took me the longest to like, because I really like the &ldquo;everything-is-a-list&rdquo;-ness of Lisp.<br>But the four basic data types of Clojure—the list (yay!), the vector, the hash-map, and the set—are well-chosen and are treated equally by the core language, which is key to their ergonomics.

Things I&rsquo;ve stumbled on

No programming language is perfect, of course, and there are some pain points I&rsquo;ve found with Clojure so far.

Too much syntax

I promise I&rsquo;m not joking with this one.<br>One thing I really like about Lisp is its uniformity of syntax: it&rsquo;s all parens and spaces.<br>The only language with less syntax is Forth, as far as I know.

Even though it&rsquo;s a Lisp (don&rsquo;t @ me), Clojure has a lot more syntax than say, Scheme.<br>There&rsquo;s (), [], {}, and #{} for sequences;<br>. and / in symbol names have special meaning;<br>and honestly, a huge turn-off for me for a while was the unquote syntax ~.<br>I really like the symmetry of ` and ,!

However, I admit...

rsquo clojure lisp language like syntax

Related Articles