I've this macro declared in a namespace named "helpers"
(defmacro reply [name-key & arguments] ;;macro use BUS, it needs to be declared in this namespace
~(<! (reply* (~name-key BUS) arguments)))
I need use it in other namespace "core" after initialized BUS in this namespace with a map
(def BUS {:something "a"})
(reply ...)
the namespace helpers only compile if BUS is declared in this namespace...I can declare it and then initialize it in my specific namespace
***helpers
(def BUS)
(declare BUS) ;;alternative
(defmacro reply... ) ;;using BUS in its body!
***other namespace
(def BUS {:a "b"})
(reply ...) ;; this macro use BUS
but this fails
BUS already refers to: #'yourvertxproject.helper-fun/BUS in namespace: test1.core, compiling:(test1/core.clj:13:1)
which is the correct way for do this?...
note: I've notice than some libs achieve this, for instance in korma db, you initialize the variable with the db path and configuration and then you can use the different functions which depends of this variable....
thanks!...
I believe you are looking for dynamic variables.
In your "helpers" namespace, declare *bus*
(not "BUS") using
(def ^:dynamic *bus*)
before creating the macro.
Then, in the namespace where you are using this, do
(binding [*bus* {:a "b"}]
...)
(Be aware that binding
is thread-local.)
In this case I would also refer the "helpers" using an :as
shortcut with a qualified namespace to make it easier to see that *bus*
is defined elsewhere.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다