title: Calculating the max of a variable number of parameters
body: <p>I'm new to Clojure so I'm wondering if someone could explain to me where I'm going wrong. I'm solving some problems in <a href="http://www.4clojure.com" rel="nofollow">4Clojure</a> to get familiar, and one of them is to calculate the max of a variable number of parameters, <em>without using Clojure's built-in max functions</em>. I'm supposed to fill in the blank:</p>
  
  <pre><code>(_ 1 8 3 4)
  </code></pre>
  
  <p>So that the result is 4.</p>
  
  <p>To this end, I am trying to implement a function of variable arity. Since everything in a Lisp has to be recursive, my base case is when there's only one element, in which case the max is the element itself. Else, I compare the first and second element, and recursively call the function in the appropriate cases:</p>
  
  <pre><code>(fn max-of
      ; base case, only one element, return the element
      ([x] x)
      ; if more than one element...
      ([x &amp; more]
          ; ...compare the first element and the second
          ; if the first element is bigger than the second
          ; drop the second element, else drop the first 
          (if (&gt; x (first more)) (max-of (cons x (rest more)))
                                 (max-of more))))
  </code></pre>
  
  <p>But this gives me:</p>
  
  <pre><code>user=&gt;     ((fn max-of
  #_=&gt;         ([x] x)
  #_=&gt;         ([x &amp; more]
  #_=&gt;             (if (&gt; x (first more)) (max-of (cons x (rest more)))
  #_=&gt;                                    (max-of more))))
  #_=&gt;     1 8 3 4)
  (8 3 4)
  </code></pre>
  
  <p>And I have no idea why this returns me a list as opposed to calling my function on said list.</p>