I have one function wait-until whose definition is like-
(defn wait-until
   [pred]
   (wait-until* pred))
where, pred is a function & wai-until* is some internal working.

Now, I want to modify it like-
(defn wait-until
   [pred]
   (try 
    (wait-until* pred)
    (catch Exception e
      (println "Exception happened for fn " pred))))

Now, for ex, input is (wait-until #(exists? ".foo")) and if wait-until* 
throws exception
it will print something like- #<taxi$eval40409$fn__40410 
clj_webdriver.taxi$eval40409$fn__40410@7b7b202f>(compiled name for that 
anonymous function)
instead of that, I want actual function body which is #(exists? ".foo").

But, I didn't get way where I can get source of anonymous function.

Instead of that I found two ways for better user message:
1. Add meta to anonymous fn and print that meta in error message, so user 
will get exact idea of where wait-until has failed.
   (defn wait-until
   [pred]
   (try 
    (wait-until* pred)
    (catch Exception e
       (when (meta pred)
          (println "Exception happened for fn with meta: " (meta pred))))))

and input will be like- (wait-until ^{:checks "existence of foo"} #(exists? 
".foo")) 
and if it throws exception,
 output will be like- Exception happened for fn with meta: {:checks 
"existence of foo"}

2. Pass pred fun in quoted form, so that wait-until fn can execute + get 
its body as it is.
   (defn wait-until
   [pred]
   (try 
    (wait-until* (exec pred))
    (catch Exception e
      (println "Exception happened for fn " pred))))

So, which way is better to go with. Or is there any other way to do?

-- 
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/d/optout.

Reply via email to