Comment

Comment by LandR

Something I discovered about Clojure's cond recently.

It usually looks likethis:

    (cond (< a b) (println "a < b")
          (> a b) (println "a > b")
          :else   (println "a = b"))
I thought the :else had to be :else, but it only needs to be truthy, so it can be anything that isn't false or nil (which makes sense as you want it to always execute that form if no others match).

So this is just the same:

   (cond (< a b) (println "a < b")
         (> a b) (println "a > b")
         :hotdog (println "a = b"))
Probably obvious to everyone else but it was a bit of a "duh, of course!" moment for me.
parent LandR 6 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton