title: Clojure macro that builds a higher order function from a function
body: <p>I'm trying to write a macro that builds middleware akin to that used in compojure.</p>
  
  <p>I want to be able to call:</p>
  
  <pre><code>(def-middleware plus-two [x]
    (+ 2 x))
  </code></pre>
  
  <p>And have the result look like:</p>
  
  <pre><code>(defn plus-two [f]
   (fn [x]
     (f (+ 2 x)))
  </code></pre>
  
  <p>I've got this far from reading on-line guides but it's not working out for me:</p>
  
  <pre><code>(defmacro def-middleware [fn-name args &amp; body]
    '(defn ~fn-name [f]
       (fn ~args
         (f ~@body))))
  </code></pre>
  
  <p>Any help or a pointer to a better macro writing guide would be great, thanks.</p>