#Clojure

Abstracting the Clojure def-macro pattern

, in Clojure

Wrapping a function in a ‘def-macro’ is a common Clojure pattern. This practice serves two purposes: providing a nicer syntax for definitions, and controlling evaluation order. Although simple to understand, this pattern is somewhat repetitive. Introducing: a higher-order macro that relieves this pain.

Reducing with for-fold

, in Clojure

Complicated reduce algorithms are still tricky for me sometimes. Clojure’s for makes map more visual, which makes it easier for me to engage my imagination. Racket extends this idea to reduce with for/fold, and also supports reducing multiple collections. Let’s port it over to Clojure.

Implementing Multimethods

, in Clojure

Multimethods are one of Clojure’s primary polymorphism mechanisms. They allow dispatch on an arbitrary number of arguments, by combining a dispatching function with one or more methods. Here’s a way to implement them.