This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-03-13
Channels
- # atlanta-clojurians (1)
- # beginners (148)
- # boot (13)
- # capetown (1)
- # cider (38)
- # cljs-dev (92)
- # clojure (61)
- # clojure-brasil (1)
- # clojure-dev (6)
- # clojure-italy (21)
- # clojure-losangeles (1)
- # clojure-nl (7)
- # clojure-norway (20)
- # clojure-spec (70)
- # clojure-uk (64)
- # clojurescript (69)
- # core-async (11)
- # cursive (6)
- # data-science (2)
- # datomic (50)
- # docker (2)
- # duct (12)
- # figwheel (1)
- # fulcro (81)
- # graphql (19)
- # jobs (3)
- # jobs-discuss (44)
- # keechma (1)
- # leiningen (1)
- # mount (2)
- # off-topic (10)
- # onyx (19)
- # parinfer (3)
- # portkey (6)
- # re-frame (4)
- # reagent (145)
- # reitit (1)
- # ring (1)
- # ring-swagger (2)
- # specter (1)
- # sql (4)
- # tools-deps (43)
- # unrepl (29)
- # vim (1)
I am trying to write a macro that creates a state in the ns that macro was called. I cannot get the ^:dynamic part working (compiler warnings telling me that it is not dynamic). Here is what I have:
(defmacro create-notification-listener [listener-name channel-name listener-fn]
`(defstate ^:dynamic ~listener-name
:start (create-notification-listener-conn ~channel-name ~listener-fn)
:stop (.close ~listener-name)))
and somewhere else:
(db/create-notification-listener *job-polling-job-listener* job-entities/job-update-channel notify-monitor!)
results in:
Warning: *job-polling-job-listener* not declared dynamic and thus is not dynamically rebindable, but its name suggests otherwise. Please either indicate ^:dynamic *job-polling-job-listener* or change the name. (campaignbot/scheduler/job_polling.clj:17)
@f.v.claus iff you really need this complexity.. of a macro within macro, you should use vary-meta
inside the macros to add to meta, and not a reader ^:dynamic
macro:
boot.user=> (defmacro foo [name] `(mount/defstate ~(vary-meta name merge {:dynamic true}) :start 42 :stop (println "stopping" ~name)))
#'boot.user/foo
boot.user=> (foo *job-polling-job-listener*)
#'boot.user/*job-polling-job-listener*
boot.user=> (mount/start #'boot.user/*job-polling-job-listener*)
{:started ["#'boot.user/*job-polling-job-listener*"]}
boot.user=> @#'boot.user/*job-polling-job-listener*
42
boot.user=> (mount/stop #'boot.user/*job-polling-job-listener*)
stopping 42
{:stopped ["#'boot.user/*job-polling-job-listener*"]}