It strikes me as a wart, albeit one that won't be much encountered, that there's no good way to discriminate between the user-defined function "catch" and the exception-catching magic symbol "catch" here:
user> (defn kick [& o] (apply println "kick the" o)) #'user/kick user> (defn catch [& o] (apply println "catch the" o)) #'user/catch user> (try (kick "ball") (catch Exception e 1)) kick the ball nil user> (let [e 1] (try (kick Exception e 1) (+ 1 2) (catch Exception e 1))) kick the java.lang.Exception 1 1 3 user> (try (catch "ball") (catch Exception e 1)) CompilerException java.lang.IllegalArgumentException: Unable to resolve classname: ball, compiling:(NO_SOURCE_PATH:1) user> (let [e 1] (try (catch Exception e 1) (+ 1 2) (catch Exception e 1))) CompilerException java.lang.RuntimeException: Only catch or finally clause can follow catch in try expression, compiling:(NO_SOURCE_PATH:1) user> There is *a* way (b): user> (try (user/catch "ball") (catch Exception e 1)) catch the ball nil But it's not a very *good* way (c): user> (let [catch (fn [& o] (println "actually, don't catch"))] (try (user/catch "ball") (catch Exception e 1))) catch the ball nil (b) works because try just looks for symbols whose first element is the symbol "catch". But the workaround fails for (c) because the let-bound symbol isn't the same as the var named user/catch, so you end up with the wrong thing. If catch (and finally, I suppose) were defined in clojure.core, then the parsing code for try could check, not that the first element of a form is the symbol 'catch, but that it resolves to the var #'clojure.core/catch. (I assume it could do that, anyway! It's implemented in Java in the compiler and I'm not sure what information is available at that point.) Since symbols from clojure.core are imported by default, in most cases it wouldn't make a difference. But in cases like (a), (b), and (c), it would allow for sane disambiguation. -- Ben Wolfson "Human kind has used its intelligence to vary the flavour of drinks, which may be sweet, aromatic, fermented or spirit-based. ... Family and social life also offer numerous other occasions to consume drinks for pleasure." [Larousse, "Drink" entry] -- -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.