gnl/ghostwheel

Make macros easier to use

thheller opened this issue · 4 comments

You example currently uses :refer-macros for CLJS. This is not necessary with one tiny tweak.

(:require [ghostwheel.core :as g
            ;; `?` is an optional shortcut for `s/nilable`
            :refer-macros [>defn >defn- >fdef ?]
            ;; Optional - you can use `:ret`, `:st` and `:gen` instead.
            :refer [=> | <-]])

Inside ghostwheel.core you only need to add a (:require-macros [ghostweel.core]) for CLJS. The compiler will then figure out when to use a macro on its own so the user only has to :refer and never :refer-macros.

(:require [ghostwheel.core :as g
            ;; `?` is an optional shortcut for `s/nilable`
            ;; Optional - you can use `:ret`, `:st` and `:gen` instead.
            :refer [>defn >defn- >fdef ? => | <-]])
gnl commented

This is fantastic Thomas, thank you. It has always been a thorn in my eye and I didn't know you could do that, will fix this for the next release.

gnl commented

Just to clarify if anyone else should be reading this - it's actually (:require-macros ghostwheel.core) without the vector, for whatever reason.
https://clojurescript.org/guides/ns-forms#_implicit_sugar

Fixed in 0.2.2, already available via the 0.2.2-SNAPSHOT.

:require-macros is just like :require and the extra vector is optional as long as you don't want to use :as or :refer for the macros inside ghostweel.core itself. As far as the macro sugar is concerned it only matters that the ns self-requires nothing else.

gnl commented

My bad, I could have sworn that (:require-macros [ghostwheel.core]) didn't compile at one point but it must have been something else, because it does now.