title: When to use a Var instead of a function?
body: <p>I am going through the book <a href="https://pragprog.com/titles/dswdcloj3/web-development-with-clojure-third-edition/" rel="nofollow noreferrer">Web Development with Clojure</a>  and it tells me to pass the handler (defined bellow) as a Var object instead of as the function itself, since the function can then change dynamically (this is what wrap-reload does).</p>
  <p>The book says:</p>
  <p>&quot;Note that we have to create a var from the handler in order for this middleware
  to work. This is necessary to ensure that the Var object containing the current
  handler function is returned. If we used the handler instead then the app would
  only see the original value of the function and changes would not be reflected.&quot;
  I don't really understand what this means, are vars similar to c pointers?</p>
  <pre><code>(ns ring-app.core
    (:require [ring.adapter.jetty :as jetty]
              [ring.util.response :as response]
              [ring.middleware.reload :refer [wrap-reload]]))
  
  (defn handler [request]
    (response/response
     (str &quot;&lt;html&gt;/&lt;body&gt; your IP is: &quot; (:remote-addr request)
          &quot;&lt;/body&gt;&lt;/html&gt;&quot;)))
  
  (defn wrap-nocache [handler]
    (fn [request]
      (-&gt; request
          handler
          (assoc-in [:headers &quot;Pragma&quot;] &quot;no-cache&quot;))))
  </code></pre>
  <p>Here is the handler call:</p>
  <pre><code>(defn -main []
    (jetty/run-jetty
     (wrap-reload (wrap-nocache  (var handler)))
     {:port 3001
      :join? false}))
  </code></pre>