Question

Example code:

(def app
  (-> #'handler
     (ring.middleware.stacktrace/wrap-stacktrace)
     (wrap-spy)))

I'm not Clojure expert and this #' baffles me -- what is that?

Was it helpful?

Solution

It's a reader macro called var-quote. #'x is the same as (var x).

What it does is give you a reference to the variable called x, and not the value referred to by x. In this case you're saying to ring, "the function to call is in handler" rather than "here's the function to call." This means you can update (redefine in repl) the definition of handler and ring will find it, even if you don't update the rest of the app.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top