Re: Get anonymous function's(which is parameter to function) body in called function

2015-05-31 Thread Leon Grapenthin
I wonder why this can't become a language feature? Couldn't Clojure attach 
the :source metadata directly to function objects (in addition to vars)? Is 
there a JIRA ticket for it? I'd instant-vote for it because I know it would 
make my debugging faster.

On Thursday, May 28, 2015 at 1:03:52 PM UTC+2, Shalaka Patil wrote:
>
> 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- # 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.


Re: Get anonymous function's(which is parameter to function) body in called function

2015-05-31 Thread Shalaka Patil
Okay. Thanks BG :)

On Saturday, May 30, 2015 at 5:13:00 AM UTC+5:30, Baishampayan Ghose wrote:
>
> May be wrap it up in a `wait-until-with-meta` macro as Herwig suggested? 
> Then you can search and replace the invocations. ~BG
>
> On Fri, May 29, 2015 at 9:30 PM, Shalaka Patil  > wrote:
>
>> Hey BG, 
>>Yes, having metadata is really a straight forward way but this is kind 
>> of extra work in every wait-until call which I was trying to avoid. Going 
>> with metadata option will not just cause extra work for wait-until in 
>> future code but even I need to add it at all the places in wherever it is 
>> used. But yes, if having `eval` is really bad way or there is no other way 
>> to handle it then will go with `metadata` approach :)
>>
>> On Friday, May 29, 2015 at 8:53:11 PM UTC+5:30, Baishampayan Ghose wrote:
>>>
>>> Shalaka,
>>>
>>> This is a really interesting conversation :-) However, I'd insist that 
>>> you ditch eval or any sort of complicated affair and adopt the metadata 
>>> approach as I had suggested that day :-P
>>>
>>> ~BG
>>>
>>> On Fri, May 29, 2015 at 4:20 PM, Shalaka Patil  
>>> wrote:
>>>
 Hey, Thanks Herwig & Mohit.

 So, I have one more solution.

 Here is the original wait-until function-


 (defn wait-until
   ([pred] (wait/wait-until *driver* (fn [_] pred)))  ([pred timeout] (
 wait/wait-until *driver* (fn [_] pred) timeout))  ([pred timeout 
 interval] (wait/wait-until *driver* (fn [_] pred) timeout interval))  
 ([driver pred timeout interval] (wait/wait-until driver (fn [d] (pred d
 )) timeout interval)))

 I have converted function to macro like - 

 (defmacro with-wait-until-error-log
   [pred & body]
   `(try
  ~@body
  (catch Exception e#
(println "\nWait-until failed for: " ~pred "\n")
e#)))


 (defmacro wait-until
   [& args]
   `(if (= (count '~args) 4)
  (let [pred# (nth '~args 1)]
(with-wait-until-error-log
  pred#
  (wait/wait-until (eval (nth '~args 0))
   (fn [_#] (eval pred#))
   (nth '~args 2)
   (nth '~args 3
  (let [pred# (first '~args)]
(with-wait-until-error-log
  pred#
  (wait/wait-until *driver* (fn [_#] (eval pred#))
   (nth '~args 1)
   (nth '~args 2))

 So, by this way I am not breaking input format or fn behaviour, but 
 need to use `eval`. So, is there any other way for doing same as eval? Or, 
 is it OK to use eval?



 On Friday, May 29, 2015 at 12:55:20 PM UTC+5:30, Mohit Thatte wrote:
>
> I see what you mean, this is nice 
>
> On Thu, May 28, 2015 at 11:25 PM, Herwig Hochleitner <
> hhochl...@gmail.com> wrote:
>
>> 2015-05-28 19:42 GMT+02:00 Mohit Thatte :
>>>
>>> The interesting question here is what constitutes useful information!
>>>
>>
>> (let [pred #(exists? ".foo")]
>>   (wait-until pred)) ;; <- the fact that it's called 'pred is not 
>> interesting in most cases
>>  
>>
>>> The trade-off is breaking an existing public API.
>>>
>>
>> How so?
>>
>> (defmacro op [msg args expr]
>>   `(with-meta (fn ~args ~expr) {:msg ~msg :args '~args :expr '~expr}))
>>
>> (let [pred1 #(exists? ".foo")
>>   pred2 (op "checks existance" [] (exists? ".foo"))]
>>   ;; both these will work, the one with pred1 will give less useful 
>> errors. the API of wait-until is unchanged
>>   (wait-until pred1)
>>   (wait-until pred2))
>>
>> If Shalaka's primary goal is prettier errors in test failures, I'd 
>>> settle for the fn body itself as the error message and that could be 
>>> achieved without breaking the API.
>>>
>>
>> The op macro can include the code in its information.
>>
>> -- 
>> You received this message because you are subscribed to the Google
>> Groups "Clojure" group.
>> To post to this group, send email to clo...@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+u...@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+u...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> -- 
> -Mohit Thatte
>  
  -- 
 You received this message because you are subscribed to the Google
 Groups "Clojure" g

Re: Get anonymous function's(which is parameter to function) body in called function

2015-05-29 Thread Baishampayan Ghose
May be wrap it up in a `wait-until-with-meta` macro as Herwig suggested?
Then you can search and replace the invocations. ~BG

On Fri, May 29, 2015 at 9:30 PM, Shalaka Patil 
wrote:

> Hey BG,
>Yes, having metadata is really a straight forward way but this is kind
> of extra work in every wait-until call which I was trying to avoid. Going
> with metadata option will not just cause extra work for wait-until in
> future code but even I need to add it at all the places in wherever it is
> used. But yes, if having `eval` is really bad way or there is no other way
> to handle it then will go with `metadata` approach :)
>
> On Friday, May 29, 2015 at 8:53:11 PM UTC+5:30, Baishampayan Ghose wrote:
>>
>> Shalaka,
>>
>> This is a really interesting conversation :-) However, I'd insist that
>> you ditch eval or any sort of complicated affair and adopt the metadata
>> approach as I had suggested that day :-P
>>
>> ~BG
>>
>> On Fri, May 29, 2015 at 4:20 PM, Shalaka Patil 
>> wrote:
>>
>>> Hey, Thanks Herwig & Mohit.
>>>
>>> So, I have one more solution.
>>>
>>> Here is the original wait-until function-
>>>
>>>
>>> (defn wait-until
>>>   ([pred] (wait/wait-until *driver* (fn [_] pred)))  ([pred timeout] (
>>> wait/wait-until *driver* (fn [_] pred) timeout))  ([pred timeout
>>> interval] (wait/wait-until *driver* (fn [_] pred) timeout interval))  
>>> ([driver
>>> pred timeout interval] (wait/wait-until driver (fn [d] (pred d))
>>> timeout interval)))
>>>
>>> I have converted function to macro like -
>>>
>>> (defmacro with-wait-until-error-log
>>>   [pred & body]
>>>   `(try
>>>  ~@body
>>>  (catch Exception e#
>>>(println "\nWait-until failed for: " ~pred "\n")
>>>e#)))
>>>
>>>
>>> (defmacro wait-until
>>>   [& args]
>>>   `(if (= (count '~args) 4)
>>>  (let [pred# (nth '~args 1)]
>>>(with-wait-until-error-log
>>>  pred#
>>>  (wait/wait-until (eval (nth '~args 0))
>>>   (fn [_#] (eval pred#))
>>>   (nth '~args 2)
>>>   (nth '~args 3
>>>  (let [pred# (first '~args)]
>>>(with-wait-until-error-log
>>>  pred#
>>>  (wait/wait-until *driver* (fn [_#] (eval pred#))
>>>   (nth '~args 1)
>>>   (nth '~args 2))
>>>
>>> So, by this way I am not breaking input format or fn behaviour, but need
>>> to use `eval`. So, is there any other way for doing same as eval? Or, is it
>>> OK to use eval?
>>>
>>>
>>>
>>> On Friday, May 29, 2015 at 12:55:20 PM UTC+5:30, Mohit Thatte wrote:

 I see what you mean, this is nice

 On Thu, May 28, 2015 at 11:25 PM, Herwig Hochleitner <
 hhochl...@gmail.com> wrote:

> 2015-05-28 19:42 GMT+02:00 Mohit Thatte :
>>
>> The interesting question here is what constitutes useful information!
>>
>
> (let [pred #(exists? ".foo")]
>   (wait-until pred)) ;; <- the fact that it's called 'pred is not
> interesting in most cases
>
>
>> The trade-off is breaking an existing public API.
>>
>
> How so?
>
> (defmacro op [msg args expr]
>   `(with-meta (fn ~args ~expr) {:msg ~msg :args '~args :expr '~expr}))
>
> (let [pred1 #(exists? ".foo")
>   pred2 (op "checks existance" [] (exists? ".foo"))]
>   ;; both these will work, the one with pred1 will give less useful
> errors. the API of wait-until is unchanged
>   (wait-until pred1)
>   (wait-until pred2))
>
> If Shalaka's primary goal is prettier errors in test failures, I'd
>> settle for the fn body itself as the error message and that could be
>> achieved without breaking the API.
>>
>
> The op macro can include the code in its information.
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clo...@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+u...@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+u...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>



 --
 -Mohit Thatte

>>>  --
>>> You received this message because you are subscribed to the Google
>>> Groups "Clojure" group.
>>> To post to this group, send email to clo...@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+u...@googlegroups.com
>>> For more opti

Re: Get anonymous function's(which is parameter to function) body in called function

2015-05-29 Thread Shalaka Patil
Hey BG, 
   Yes, having metadata is really a straight forward way but this is kind 
of extra work in every wait-until call which I was trying to avoid. Going 
with metadata option will not just cause extra work for wait-until in 
future code but even I need to add it at all the places in wherever it is 
used. But yes, if having `eval` is really bad way or there is no other way 
to handle it then will go with `metadata` approach :)

On Friday, May 29, 2015 at 8:53:11 PM UTC+5:30, Baishampayan Ghose wrote:
>
> Shalaka,
>
> This is a really interesting conversation :-) However, I'd insist that you 
> ditch eval or any sort of complicated affair and adopt the metadata 
> approach as I had suggested that day :-P
>
> ~BG
>
> On Fri, May 29, 2015 at 4:20 PM, Shalaka Patil  > wrote:
>
>> Hey, Thanks Herwig & Mohit.
>>
>> So, I have one more solution.
>>
>> Here is the original wait-until function-
>>
>>
>> (defn wait-until
>>   ([pred] (wait/wait-until *driver* (fn [_] pred)))  ([pred timeout] (
>> wait/wait-until *driver* (fn [_] pred) timeout))  ([pred timeout interval
>> ] (wait/wait-until *driver* (fn [_] pred) timeout interval))  ([driver 
>> pred timeout interval] (wait/wait-until driver (fn [d] (pred d)) timeout 
>> interval)))
>>
>> I have converted function to macro like - 
>>
>> (defmacro with-wait-until-error-log
>>   [pred & body]
>>   `(try
>>  ~@body
>>  (catch Exception e#
>>(println "\nWait-until failed for: " ~pred "\n")
>>e#)))
>>
>>
>> (defmacro wait-until
>>   [& args]
>>   `(if (= (count '~args) 4)
>>  (let [pred# (nth '~args 1)]
>>(with-wait-until-error-log
>>  pred#
>>  (wait/wait-until (eval (nth '~args 0))
>>   (fn [_#] (eval pred#))
>>   (nth '~args 2)
>>   (nth '~args 3
>>  (let [pred# (first '~args)]
>>(with-wait-until-error-log
>>  pred#
>>  (wait/wait-until *driver* (fn [_#] (eval pred#))
>>   (nth '~args 1)
>>   (nth '~args 2))
>>
>> So, by this way I am not breaking input format or fn behaviour, but need 
>> to use `eval`. So, is there any other way for doing same as eval? Or, is it 
>> OK to use eval?
>>
>>
>>
>> On Friday, May 29, 2015 at 12:55:20 PM UTC+5:30, Mohit Thatte wrote:
>>>
>>> I see what you mean, this is nice 
>>>
>>> On Thu, May 28, 2015 at 11:25 PM, Herwig Hochleitner <
>>> hhochl...@gmail.com> wrote:
>>>
 2015-05-28 19:42 GMT+02:00 Mohit Thatte :
>
> The interesting question here is what constitutes useful information!
>

 (let [pred #(exists? ".foo")]
   (wait-until pred)) ;; <- the fact that it's called 'pred is not 
 interesting in most cases
  

> The trade-off is breaking an existing public API.
>

 How so?

 (defmacro op [msg args expr]
   `(with-meta (fn ~args ~expr) {:msg ~msg :args '~args :expr '~expr}))

 (let [pred1 #(exists? ".foo")
   pred2 (op "checks existance" [] (exists? ".foo"))]
   ;; both these will work, the one with pred1 will give less useful 
 errors. the API of wait-until is unchanged
   (wait-until pred1)
   (wait-until pred2))

 If Shalaka's primary goal is prettier errors in test failures, I'd 
> settle for the fn body itself as the error message and that could be 
> achieved without breaking the API.
>

 The op macro can include the code in its information.

 -- 
 You received this message because you are subscribed to the Google
 Groups "Clojure" group.
 To post to this group, send email to clo...@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+u...@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+u...@googlegroups.com.
 For more options, visit https://groups.google.com/d/optout.

>>>
>>>
>>>
>>> -- 
>>> -Mohit Thatte
>>>  
>>  -- 
>> You received this message because you are subscribed to the Google
>> Groups "Clojure" group.
>> To post to this group, send email to clo...@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+u...@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+u...@googlegroups.com 

Re: Get anonymous function's(which is parameter to function) body in called function

2015-05-29 Thread Baishampayan Ghose
Shalaka,

This is a really interesting conversation :-) However, I'd insist that you
ditch eval or any sort of complicated affair and adopt the metadata
approach as I had suggested that day :-P

~BG

On Fri, May 29, 2015 at 4:20 PM, Shalaka Patil 
wrote:

> Hey, Thanks Herwig & Mohit.
>
> So, I have one more solution.
>
> Here is the original wait-until function-
>
>
> (defn wait-until
>   ([pred] (wait/wait-until *driver* (fn [_] pred)))  ([pred timeout] (wait
> /wait-until *driver* (fn [_] pred) timeout))  ([pred timeout interval] (
> wait/wait-until *driver* (fn [_] pred) timeout interval))  ([driver pred
> timeout interval] (wait/wait-until driver (fn [d] (pred d)) timeout
> interval)))
>
> I have converted function to macro like -
>
> (defmacro with-wait-until-error-log
>   [pred & body]
>   `(try
>  ~@body
>  (catch Exception e#
>(println "\nWait-until failed for: " ~pred "\n")
>e#)))
>
>
> (defmacro wait-until
>   [& args]
>   `(if (= (count '~args) 4)
>  (let [pred# (nth '~args 1)]
>(with-wait-until-error-log
>  pred#
>  (wait/wait-until (eval (nth '~args 0))
>   (fn [_#] (eval pred#))
>   (nth '~args 2)
>   (nth '~args 3
>  (let [pred# (first '~args)]
>(with-wait-until-error-log
>  pred#
>  (wait/wait-until *driver* (fn [_#] (eval pred#))
>   (nth '~args 1)
>   (nth '~args 2))
>
> So, by this way I am not breaking input format or fn behaviour, but need
> to use `eval`. So, is there any other way for doing same as eval? Or, is it
> OK to use eval?
>
>
>
> On Friday, May 29, 2015 at 12:55:20 PM UTC+5:30, Mohit Thatte wrote:
>>
>> I see what you mean, this is nice
>>
>> On Thu, May 28, 2015 at 11:25 PM, Herwig Hochleitner > > wrote:
>>
>>> 2015-05-28 19:42 GMT+02:00 Mohit Thatte :

 The interesting question here is what constitutes useful information!

>>>
>>> (let [pred #(exists? ".foo")]
>>>   (wait-until pred)) ;; <- the fact that it's called 'pred is not
>>> interesting in most cases
>>>
>>>
 The trade-off is breaking an existing public API.

>>>
>>> How so?
>>>
>>> (defmacro op [msg args expr]
>>>   `(with-meta (fn ~args ~expr) {:msg ~msg :args '~args :expr '~expr}))
>>>
>>> (let [pred1 #(exists? ".foo")
>>>   pred2 (op "checks existance" [] (exists? ".foo"))]
>>>   ;; both these will work, the one with pred1 will give less useful
>>> errors. the API of wait-until is unchanged
>>>   (wait-until pred1)
>>>   (wait-until pred2))
>>>
>>> If Shalaka's primary goal is prettier errors in test failures, I'd
 settle for the fn body itself as the error message and that could be
 achieved without breaking the API.

>>>
>>> The op macro can include the code in its information.
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Clojure" group.
>>> To post to this group, send email to clo...@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+u...@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+u...@googlegroups.com.
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
>>
>> --
>> -Mohit Thatte
>>
>  --
> 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.
>



-- 
Baishampayan Ghose
b.ghose at gmail.com

-- 
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 a

Re: Get anonymous function's(which is parameter to function) body in called function

2015-05-29 Thread Shalaka Patil
Hey, Thanks Herwig & Mohit.

So, I have one more solution.

Here is the original wait-until function-


(defn wait-until
  ([pred] (wait/wait-until *driver* (fn [_] pred)))  ([pred timeout] (wait/
wait-until *driver* (fn [_] pred) timeout))  ([pred timeout interval] (wait/
wait-until *driver* (fn [_] pred) timeout interval))  ([driver pred timeout 
interval] (wait/wait-until driver (fn [d] (pred d)) timeout interval)))

I have converted function to macro like - 

(defmacro with-wait-until-error-log
  [pred & body]
  `(try
 ~@body
 (catch Exception e#
   (println "\nWait-until failed for: " ~pred "\n")
   e#)))


(defmacro wait-until
  [& args]
  `(if (= (count '~args) 4)
 (let [pred# (nth '~args 1)]
   (with-wait-until-error-log
 pred#
 (wait/wait-until (eval (nth '~args 0))
  (fn [_#] (eval pred#))
  (nth '~args 2)
  (nth '~args 3
 (let [pred# (first '~args)]
   (with-wait-until-error-log
 pred#
 (wait/wait-until *driver* (fn [_#] (eval pred#))
  (nth '~args 1)
  (nth '~args 2))

So, by this way I am not breaking input format or fn behaviour, but need to 
use `eval`. So, is there any other way for doing same as eval? Or, is it OK 
to use eval?



On Friday, May 29, 2015 at 12:55:20 PM UTC+5:30, Mohit Thatte wrote:
>
> I see what you mean, this is nice 
>
> On Thu, May 28, 2015 at 11:25 PM, Herwig Hochleitner  > wrote:
>
>> 2015-05-28 19:42 GMT+02:00 Mohit Thatte > >:
>>>
>>> The interesting question here is what constitutes useful information!
>>>
>>
>> (let [pred #(exists? ".foo")]
>>   (wait-until pred)) ;; <- the fact that it's called 'pred is not 
>> interesting in most cases
>>  
>>
>>> The trade-off is breaking an existing public API.
>>>
>>
>> How so?
>>
>> (defmacro op [msg args expr]
>>   `(with-meta (fn ~args ~expr) {:msg ~msg :args '~args :expr '~expr}))
>>
>> (let [pred1 #(exists? ".foo")
>>   pred2 (op "checks existance" [] (exists? ".foo"))]
>>   ;; both these will work, the one with pred1 will give less useful 
>> errors. the API of wait-until is unchanged
>>   (wait-until pred1)
>>   (wait-until pred2))
>>
>> If Shalaka's primary goal is prettier errors in test failures, I'd settle 
>>> for the fn body itself as the error message and that could be achieved 
>>> without breaking the API.
>>>
>>
>> The op macro can include the code in its information.
>>
>> -- 
>> You received this message because you are subscribed to the Google
>> Groups "Clojure" group.
>> To post to this group, send email to clo...@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+u...@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+u...@googlegroups.com .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> -- 
> -Mohit Thatte
>  

-- 
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.


Re: Get anonymous function's(which is parameter to function) body in called function

2015-05-29 Thread Mohit Thatte
I see what you mean, this is nice [?]

On Thu, May 28, 2015 at 11:25 PM, Herwig Hochleitner  wrote:

> 2015-05-28 19:42 GMT+02:00 Mohit Thatte :
>>
>> The interesting question here is what constitutes useful information!
>>
>
> (let [pred #(exists? ".foo")]
>   (wait-until pred)) ;; <- the fact that it's called 'pred is not
> interesting in most cases
>
>
>> The trade-off is breaking an existing public API.
>>
>
> How so?
>
> (defmacro op [msg args expr]
>   `(with-meta (fn ~args ~expr) {:msg ~msg :args '~args :expr '~expr}))
>
> (let [pred1 #(exists? ".foo")
>   pred2 (op "checks existance" [] (exists? ".foo"))]
>   ;; both these will work, the one with pred1 will give less useful
> errors. the API of wait-until is unchanged
>   (wait-until pred1)
>   (wait-until pred2))
>
> If Shalaka's primary goal is prettier errors in test failures, I'd settle
>> for the fn body itself as the error message and that could be achieved
>> without breaking the API.
>>
>
> The op macro can include the code in its information.
>
> --
> 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.
>



-- 
-Mohit Thatte

-- 
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.


Re: Get anonymous function's(which is parameter to function) body in called function

2015-05-28 Thread Herwig Hochleitner
2015-05-28 19:42 GMT+02:00 Mohit Thatte :
>
> The interesting question here is what constitutes useful information!
>

(let [pred #(exists? ".foo")]
  (wait-until pred)) ;; <- the fact that it's called 'pred is not
interesting in most cases


> The trade-off is breaking an existing public API.
>

How so?

(defmacro op [msg args expr]
  `(with-meta (fn ~args ~expr) {:msg ~msg :args '~args :expr '~expr}))

(let [pred1 #(exists? ".foo")
  pred2 (op "checks existance" [] (exists? ".foo"))]
  ;; both these will work, the one with pred1 will give less useful errors.
the API of wait-until is unchanged
  (wait-until pred1)
  (wait-until pred2))

If Shalaka's primary goal is prettier errors in test failures, I'd settle
> for the fn body itself as the error message and that could be achieved
> without breaking the API.
>

The op macro can include the code in its information.

-- 
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.


Re: Get anonymous function's(which is parameter to function) body in called function

2015-05-28 Thread Mohit Thatte
"but it won't give useful information if you don't construct the op inline."

The interesting question here is what constitutes useful information! The
trade-off is breaking an existing public API.

If Shalaka's primary goal is prettier errors in test failures, I'd settle
for the fn body itself as the error message and that could be achieved
without breaking the API.



On Thu, May 28, 2015 at 11:04 PM, Herwig Hochleitner  wrote:

> 2015-05-28 19:22 GMT+02:00 Mohit Thatte :
>
>> Changing wait-until to a macro seems like the simplest way to tackle
>> this. It gives you access to pred at compile time, does not force the
>> caller to add meta-data to pred, and you can construct the error message as
>> you like.
>>
>
> I was actually thinking about constructing the fns you pass to
> `wait-until` with a macro (defop, ..).
>
> The challenge with your approach 1 would be to change all existing calls
>> to wait-until and add meta to them.
>>
>
> Making `wait-until` a macro may  provide a way around that, but it won't
> give useful information if you don't construct the op inline.
>
> --
> 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.
>



-- 
-Mohit Thatte

-- 
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.


Re: Get anonymous function's(which is parameter to function) body in called function

2015-05-28 Thread Herwig Hochleitner
2015-05-28 19:22 GMT+02:00 Mohit Thatte :

> Changing wait-until to a macro seems like the simplest way to tackle this.
> It gives you access to pred at compile time, does not force the caller to
> add meta-data to pred, and you can construct the error message as you like.
>

I was actually thinking about constructing the fns you pass to `wait-until`
with a macro (defop, ..).

The challenge with your approach 1 would be to change all existing calls to
> wait-until and add meta to them.
>

Making `wait-until` a macro may  provide a way around that, but it won't
give useful information if you don't construct the op inline.

-- 
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.


Re: Get anonymous function's(which is parameter to function) body in called function

2015-05-28 Thread Mohit Thatte
Hi Shalaka,

+1 to what Herwig said.

Changing wait-until to a macro seems like the simplest way to tackle this.
It gives you access to pred at compile time, does not force the caller to
add meta-data to pred, and you can construct the error message as you like.

The challenge with your approach 1 would be to change all existing calls to
wait-until and add meta to them.

~M

On Thu, May 28, 2015 at 10:21 PM, Herwig Hochleitner  wrote:

> I'd definitely go with 1.), because the `exec` in 2.) is basically `eval`
> and thus should be used most sparingly.
> You can also expand on 1.) by using a macro, that stores the source and
> other debugging information in metadata and thus get all the benefits of
> 2.) and then some.
>
>  --
> 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.
>



-- 
-Mohit Thatte

-- 
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.


Re: Get anonymous function's(which is parameter to function) body in called function

2015-05-28 Thread Herwig Hochleitner
I'd definitely go with 1.), because the `exec` in 2.) is basically `eval`
and thus should be used most sparingly.
You can also expand on 1.) by using a macro, that stores the source and
other debugging information in metadata and thus get all the benefits of
2.) and then some.

-- 
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.


Get anonymous function's(which is parameter to function) body in called function

2015-05-28 Thread Shalaka Patil
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- #(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.