On Mar 19, 12:02 am, Ken Wesson wrote:
> It occurs to me you probably only want the delay between successive
> retries, so really you want to put the delay in the retrying code, or
> maybe use interpose in some manner (and make the interposed delay
> function look like a failure to the surrounding
It occurs to me you probably only want the delay between successive
retries, so really you want to put the delay in the retrying code, or
maybe use interpose in some manner (and make the interposed delay
function look like a failure to the surrounding loop).
--
You received this message because y
On Mar 19, 2:27 am, Ken Wesson wrote:
> On Fri, Mar 18, 2011 at 1:13 PM, Shantanu Kumar
>
> wrote:
> > The `try-times` macro above is buggy (doesn't work when body of code
> > returns logical false). Fixed version is below:
>
> > (defmacro try-times
> > [n & body] {:pre [(posnum? n)]}
> > `(l
https://github.com/joegallo/robert-bruce
for retrying things
On Fri, Mar 18, 2011 at 6:36 PM, Fiel
wrote:
> Thank you to all who posted all the helpful examples. I'm sure these
> will help other clojure learners too.
>
> On Mar 18, 5:27 pm, Ken Wesson wrote:
>> On Fri, Mar 18, 2011 at 1:13 PM,
Thank you to all who posted all the helpful examples. I'm sure these
will help other clojure learners too.
On Mar 18, 5:27 pm, Ken Wesson wrote:
> On Fri, Mar 18, 2011 at 1:13 PM, Shantanu Kumar
>
> wrote:
> > The `try-times` macro above is buggy (doesn't work when body of code
> > returns logic
On Fri, Mar 18, 2011 at 1:13 PM, Shantanu Kumar
wrote:
> The `try-times` macro above is buggy (doesn't work when body of code
> returns logical false). Fixed version is below:
>
> (defmacro try-times
> [n & body] {:pre [(posnum? n)]}
> `(let [c# (repeat-exec (dec ~n) #(maybe ~@body))
> r
On Mar 18, 8:08 pm, Shantanu Kumar wrote:
> An alternate way of doing it:
>
> (defmacro maybe
> [& body]
> `(try [(do ~@body) nil]
> (catch Exception e#
> [nil e#])))
>
> (defn repeat-exec
> ([f]
> (let [run (fn g[] (cons (f) (lazy-seq (g]
> (run)))
> ([n f]
>
If you need a library for automatic retry (which it sounds like from
your example), I'd check out this sweet library by Joe Gallo:
https://github.com/joegallo/robert-bruce (it uses trampolining
retries).
- Lee
--
You received this message because you are subscribed to the Google
Groups "Clojure"
On Fri, Mar 18, 2011 at 8:44 PM, Shantanu Kumar
wrote:
> This of course won't work when the body of code returns nil.
Mine would :)
Regards,
BG
--
Baishampayan Ghose
b.ghose at gmail.com
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to
Here's a version with a similar simulated exception but caught in the
main loop, with a bit of tracing code to show the retries.
Clojure 1.2.0
user=> (import java.io.IOException)
java.io.IOException
user=>
user=> (defn some-io-operation []
(let [n (rand-int 30)]
(if (> n 10)
(throw (I
This of course won't work when the body of code returns nil.
Regards,
Shantanu
On Mar 18, 8:08 pm, Shantanu Kumar wrote:
> An alternate way of doing it:
>
> (defmacro maybe
> [& body]
> `(try [(do ~@body) nil]
> (catch Exception e#
> [nil e#])))
>
> (defn repeat-exec
> ([f]
>
An alternate way of doing it:
(defmacro maybe
[& body]
`(try [(do ~@body) nil]
(catch Exception e#
[nil e#])))
(defn repeat-exec
([f]
(let [run (fn g[] (cons (f) (lazy-seq (g]
(run)))
([n f]
(take n (repeat-exec f
(defmacro try-times
[n & body]
`(let
On Fri, Mar 18, 2011 at 7:19 AM, Fiel Cabral
wrote:
> public String loop_with_exception(int retries)
> {
> for (int n = retries; n > 0; n--) {
> try {
> return some_io_operation();
> } catch (IOException e) {
> continue;
> }
> }
> return null;
> }
This is how I would
On Thu Mar 17 21:49 2011, Fiel Cabral wrote:
> Hello Clojure users,
> This is a dumb question but I'd like to write something equivalent to this
> in Clojure:
>
> public String loop_with_exception(int retries)
> {
> for (int n = retries; n > 0; n--) {
> try {
> return some_io_operation
Notice it says "can't recur from within a catch". So throw the
try/catch into it's own function and return nil if the try fails. Then
throw a if statement to continue the loop only if the function return
nil.
Timothy
On Thu, Mar 17, 2011 at 8:49 PM, Fiel Cabral
wrote:
> Hello Clojure users,
> T
Hello Clojure users,
This is a dumb question but I'd like to write something equivalent to this
in Clojure:
public String loop_with_exception(int retries)
{
for (int n = retries; n > 0; n--) {
try {
return some_io_operation();
} catch (IOException e) {
continue;
}
}
r
16 matches
Mail list logo