0

I learned that wrap-reload from ring needs to capture the var itself not the value, but what if my value is dynamically generated and not a top level var?

(defn -main [options]
  (let [app (make-app options)]
    ;; This won't work either:
    ;; (run-jetty (wrap-reload #'app))
    (run-jetty (wrap-reload app))
  ))
adamsmith
  • 5,759
  • 4
  • 27
  • 39
  • I think this does not work. You want to run `make-app` at some point to create the new app. So I'd leave the main for what it is now and put a `(def app (make-app ["-p", "8080"]))` or whatever in user.clj and a bit of tooling to start/stop jetty for REPL/reload (or opt in for one of the reload workflows). – cfrick Jan 16 '20 at 08:55
  • @cfrick sure that's one workaround. Since `wrap-reload` works based on namespace, I suppose there is a solution if we can find the namespace of a `var?` in let bindings. – adamsmith Jan 16 '20 at 09:11
  • I don't think it can pickup a change to `make-app` without calling it again. – cfrick Jan 16 '20 at 09:36
  • haha, that's really a good point! I guess I'll just use that workaround now. Thanks @cfrick – adamsmith Jan 16 '20 at 09:45

1 Answers1

0

Clojure let bindings do not create a Var object, so you cannot use the trick of passing (var app) (or it's shortcut #'app) in place of the function object that app points to.

Please see the following for more detail: When to use a Var instead of a function?

Alan Thompson
  • 29,276
  • 6
  • 41
  • 48