|
|
|
|
|
by Rovanion
1645 days ago
|
|
I think the lack of reader macros really help here. Macros in Clojure are much more "functions that run at compile time" rather than "look at this fun DSL I threw together". What I think it comes down to though is adherence to convention. A preference hierarchy has grown together with Clojure and it goes: 1. Can it be expressed using data structures, do that. For example a map/dictionary lookup.
2. If that fails, express your more complex idea using a function.
3. If you absolutely must, write a macro. You usually end up with very few macros except for those in the standard library, and those you end up with are more commonly of the convenience kind. One example would be the standard web routing library of the early 10's called Compojure that relied heavily on macros where my current favourite Reitit uses just data. |
|
Re-frame has just one, and it looks like it’s used for testing. Clara-rules has eight that are used in the library, which implements a forward-chaining Rete rule engine. Core.logic has a handful, and that’s essentially “prolog inside Clojure.” So clearly those libraries get a lot of mileage out of data and functions, with just a dash of macro.
I have yet to reach for them myself, and I can’t imagine a situation where I’d need a macro instead of a function. I think they’re probably great for library developers who are smarter than me, and I’m happy to leave them to it.