Get the latest tech news

Clojure macros continue to surprise me


have two modes: avoid them at all costs/do very basic stuff, or go absolutely crazy. Here’s the problem: I’m working on Humble UI’s component library, and I wanted to document it.

Clojure macros have two modes: avoid them at all costs/do very basic stuff, or go absolutely crazy. Unfortunately, this approach reformats code: while in the macro, all we have is an already parsed AST (data structures only, no whitespaces) and we have to pretty-print it from scratch, adding indents and newlines. You’d need a parser, a build step... Here—just ten lines of code, on vanilla language, no tooling or setup required.

Get the Android app

Or read this on Hacker News

Read more on:

Photo of Clojure

Clojure

Photo of Clojure macros

Clojure macros

Related news:

News photo

A simple core.async job system in Clojure

News photo

Try Clojure

News photo

Aggregating all cinema showtimes in Germany with Clojure