Awesome ... thanks a bunch Carlo :)

On Wednesday, May 21, 2014 8:53:18 PM UTC-6, David Gartner wrote:
>
> A totally noob question so please bear with me ... I'm trying to pass a 
> function to another function in the REPL like so:
>
> function number 1:
>
> (defn div [x y]
>  (/ x y))
>
> function number 2:
> ;; this is from the "joy of clojure"
>
> (defn throw-catch [f]
>   [(try
>     (f)
>     (catch ArithmeticException e "No dividing by zero!")
>     (catch Exception e (str "You are so bad " (.getMessage e)))
>     (finally (println "returning... ")))])
>
>
> throw-catch works as expected if I use an anonymous function as shown in 
> the book. But what I'd like to do is pass my div function to the 
> throw-catch function. I've tried a number of iterations but "throw-catch" 
> always throws an exception
>
> (throw-catch div 10 2) ;; throws an exception
> (throw-catch '(div 10 2)) ;; throws an exception
> (throw-catch [div 10 2]) ;; throws an exception ... you get the idea
>
> (throw-catch #(/ 10 5));; returns 2
>
> Can anyone enlighten me?
>
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
[email protected]
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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to