Cover image for Clojure 101 / operator precedence

Clojure 101 / operator precedence

icncsx profile image DH Kim ・1 min read

Surprise! I tricked you (πŸ˜†). There is no operator precedence in Clojure because there are no operators - only functions and arguments.

All functions evaluate left to right and inside out. Function first, then args.

(/ 1 2)
(/ 500 20)
(= "foo" "bar")
(not true)

Ok, that seems trivial. How about something more complicated?

(defn leap-year? [year]
      (= (rem year 4) 0)
      (> (rem year 100) 0))
    (= (rem year 400) 0)))

I'm telling you this is such an underrated feature of using Clojure. I can focus on memorizing the important stuff - not horrendously lengthy precedence tables such as this:

Alt Text

Now can you figure out what this does in JavaScript?

3 > 2 && 2 > 1

Apparently, it returns true. I love you JavaScript, but we need a break... truly...


Posted on by:

icncsx profile

DH Kim


Software engineer interested in cloud computing and serverless backend services.


markdown guide