5 ms·
I don't know, the community in general tend to use macros that are well written. I keep seeing core.async being used (`go`) in Clojure projects, and also variou
by capableweb 4y ago
I don't know, the community in general tend to use macros that are well written. I keep seeing core.async being used (`go`) in Clojure projects, and also various macros for writing HTTP servers (compojure being a popular one which main code interface is a macro `defroutes`).
ClojureScript projects also routinely add support for making asynchronous code look synchronous (like `async/await` in vanilla JavaScript) via macros. shadow-cljs's `js-await` being one of the well-written ones: https://github.com/thheller/shadow-cljs/blob/49fb078b834e64f63122e3a8ad3ddcd1f4485969/src/main/shadow/cljs/modern.cljc#L310-L326 https://github.com/thheller/shadow-cljs/blob/49fb078b834e64f...
Usage:
(defn my-async-fn [foo]
(js-await [the-result (promise-producing-call foo)]
(doing-something-with-the-result the-result)
(catch failure
(prn [:oh-oh failure])))
I'd say if adding a macro makes things harder to understand, you probably need to re-evaluate if you really should have a macro here, or the interface of the macro.
- moomin 4y agoYeah, there’s a couple of widely understood idioms like global static configuration and adding async/await. But the macros I’m talking about were very simple, well-defined things that exist in other languages. They were just unfamiliar. In any event, they’re ripped out now. But ultimately macros offer a lot more in theory than in practice.