The syntax of Clojure is simple and uniform. In order to enable learnable programming, people should not have to think hard about syntax. When I look at code in other languages, I see so much syntax that I don't even want to think about learning it.
An excerpt from my notes on The Joy of Clojure
In Clojure, just about everything you'll do is (operator argument argument). The fact that it's a lot of parentheses doesn't scare me… if anything, it makes it look more uniform and consistent.
Some example functions:
(+ 1 2)
; adds 1 and 2
(+ 3 (/ 6 2))
; adds 3 and 3
(define x "hello")
; defines the var x as the string "hello"
(reverse [1 2 3 4])
;reverses the order to '(4 3 2 1)
You can even use Parinfer to make it so Clojure is basically an indentation language, reducing the syntax overhead even more. You barely need to pay attention to parentheses, they're more or less just a prefix at that point.
But here's something awesome too: Parinfer is a structural editor that infers your parentheses from your indentation, so everything will be balanced and visually pleasing. Even less syntax to think about. Quick little video to show what I'm talking about https://t.co/08NAkUBlAN
— Robert Haisfield (@RobertHaisfield) May 14, 2021
I love that functions can be treated as arguments for other functions. Clojure (and Lisp more generally) is so composable that I am able to make extremely simple and direct fill in the blank functions. See Direct functions and end-user programmingDirect functions and end-user programming
Just a little anecdote of a small project:
I needed to make a program to resize images in a weird way for GuidedTrack. Instead of scaling images, I needed to add whitespace to the horizontal margins. As far as I could tell, Clojure didn't have many pre-built libraries for it, so I switched to Racket, where it seemed to have some specific functions out of the box to do what I wanted. I figured a Lisp is a Lisp so it couldn't be that different. I was able to make a function in 6 lines of code .... The fact that Clojure is programmed to abstractionsClojure is programmed to abstractions
This is a dense topic, but the short version is:
Clojure has many different data types. Maps, vectors, and lists are all different data types, but you can generally use the same functions to work with them because, abstractly, they're all sequences. This means you need to learn fewer primitives and functions are more likely to work on whatever data type you're using if you think they will.
See the first couple of sections of Chapter 4 of Clojure for the Brave and True for more details.
means that Clojure is basically just sequence manipulation.
I also love the The data-driven programming mental modelThe data-driven programming mental model
One of the core mental models of Clojure is: Write data structures. Create functions that take that data as input and create new data structures as their output, and flow the output of those into other functions. Essentially, model the world through data and its transformations.
One of my biggest motivations to learn Clojure is to explore the idea of Domain-specific languages as end-user software. Given the data-driven programming mental model, DSL creation would be just creating a notation ....
This thread has more of my early thoughts on that:
I just want to use Clojure data structures (composable collections) and functions to model out and visualize systems I'm working with. I see what people say when they describe Clojure as a tool for thought.
— Robert Haisfield (@RobertHaisfield) May 6, 2021