Fork me on GitHub
David Pham07:07:54

Morning 🙂


morning from the :flag-be: side


nice to be out of berlin for a change


@otfrom are you still stumped?


life (and a big machine) have just ground that stump down

Ben Hammond10:07:25

is it like the ending of Fantastic Mr Fox?


Hi all! Please forgive me, this is a somewhat lengthy question: We have a rather big Clojure/ClojureScript cross-compiling project which is great and fun and runs smooth as silk. I'm really happy with it. Of course we use some – not a lot – macros. If you setup a namespace like this:

(ns your.namespace.with.macros
  #?(:cljs (:require-macros [your.namespace.with.macros])))

(defmacro your-awesome-magic
  ;; ...
in a .cljc file, the macro will be exposed and will be available. So you can require that namespace in Clojure and ClojureScript. This is because of evil magic called Implicit macro loading (see for details). If you change it a little:
(ns your.namespace.with.macros
  #?(:cljs (:require-macros [your.namespace.with.macros])))

(defn macro-helper
  ;; ....

(defmacro your-awesome-magic
  ;; ...
it stays the same, but macro-helper will also be exposed and available when requiring that namespace. But be aware that there is something subtle going on: For ClojureScript, this file get's compiled twice: Once for the Clojure world, because this is where macros live, and once more for the ClojureScript world. That means that macro-helper will also be compiled in Clojure as well as in ClojureScript, although – in this case – it's not needed in the Clojure world, because it's not needed by the code run by the macro. It's needed later by the code produced by the macro. So macro-helper is compiled by Clojure in the macro compilation phase but never needed. Not a big problem. Except when it is: In our case, macro-helper can not be compiled by the Clojure compiler in the macro compilation phase when targeting ClojureScript. It can be compiled when targeting Clojure. That is because of the source paths and library setups. So the reader macros for :clj and :cljs won't help. The reader macro I need would be :clj-except-when-compiling-macros-for-cljs or something like that. The only solution I found: Move macro-helper to another namespace and require both. It works, of course, but I don't like it. If there is the slightest chance that I was able to explain the problem, any help would be much appreciated. And sorry for the lengthy post.


@ramart I think I'm using macrovich to address that problem


By the Grande cgrand? I'll have a look at it. Thanks! (Also for [clj-kondo), babashka, sci and so much more! 😍)


haha, welcome. And thanks for organizing ClojureD, I'm glad we got to visit it just before the virus thing happened

🍻 3

Why does it harm that macro-helper is compiled for clj-only code?


Because it's required by the code produced by the macro and must therefore be available in the ClojureScript world.


But @U04V15CAJ pointed me to the right direction. And it's also a good opportunity to write Christophe a mail. 😀


Yes, thanks. The major difference is that we also target Clojure. So the mentioned inverse* function of the linked article needs to be available in Clojure and ClojureScript but not during macro compilation, because it does not compile then. But exactly solves that problem. > Because any macros problem can be solved by another level of macros – Christophe Grand