Re: Can't "recur" from within a "catch" expression.

2011-03-19 Thread Shree Mulay
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

Re: Can't "recur" from within a "catch" expression.

2011-03-18 Thread Ken Wesson
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

Re: Can't "recur" from within a "catch" expression.

2011-03-18 Thread Shantanu Kumar
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

Re: Can't "recur" from within a "catch" expression.

2011-03-18 Thread Kevin Downey
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,

Re: Can't "recur" from within a "catch" expression.

2011-03-18 Thread Fiel
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

Re: Can't "recur" from within a "catch" expression.

2011-03-18 Thread Ken Wesson
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

Re: Can't "recur" from within a "catch" expression.

2011-03-18 Thread Shantanu Kumar
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] >  

Re: Can't "recur" from within a "catch" expression.

2011-03-18 Thread Lee Hinman
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"

Re: Can't "recur" from within a "catch" expression.

2011-03-18 Thread Baishampayan Ghose
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

Re: Can't "recur" from within a "catch" expression.

2011-03-18 Thread Armando Blancas
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

Re: Can't "recur" from within a "catch" expression.

2011-03-18 Thread Shantanu Kumar
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] >  

Re: Can't "recur" from within a "catch" expression.

2011-03-18 Thread Shantanu Kumar
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

Re: Can't "recur" from within a "catch" expression.

2011-03-18 Thread Baishampayan Ghose
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

Re: Can't "recur" from within a "catch" expression.

2011-03-18 Thread Daniel Solano Gomez
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

Re: Can't "recur" from within a "catch" expression.

2011-03-18 Thread Timothy Baldridge
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

Can't "recur" from within a "catch" expression.

2011-03-18 Thread Fiel Cabral
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