title: Clojure, macro that expands to execute a list with code
body: <p>Ok so I have this macro that is supposed to take a varying number of arguments and then execute them with try and catch. I am assuming that if the argument list <code>arg-list</code> is bigger then 2 then the first element in the list is a binding, like this <code>[a 0]</code> for example. So <code>arg-list</code> may look like this: <code>([s (FileReader. (File. "text.txt"))] (. s read))</code>.</p>
  
  <p>This is what I've come up with:</p>
  
  <pre><code>(defmacro safe [&amp; arg-list] (list 'if (list '&lt; (list 'count arg-list) '2)
      (list 'try (list 'eval arg-list) (list 'catch 'Exception 'e 'e))
      (list 'do (list 'eval arg-list) (list 'try (list 'eval (list 'rest arg-list)) (list 'catch 'Exception 'e 'e)))))
  </code></pre>
  
  <p>I have been struggling to get this to work for like two straight days now, but it never works. When I try this macro with for example this:</p>
  
  <pre><code>(safe (+ 2 3))
  </code></pre>
  
  <p>i get this error:</p>
  
  <pre><code>ClassCastException java.lang.Long cannot be cast to clojure.lang.IFn  user/eval91 (NO_SOURCE_FILE:100)
  </code></pre>
  
  <p>I have only been working with Clojure for four days so forgive me if my code is bad.</p>