From: Robert Klemme Date: 2005-03-27T20:34:47+09:00 Subject: Re: Evaluator for a mini-Ruby in Haskell "Phil Tomson" schrieb im Newsbeitrag news:d24b8d02fq1@enews4.newsguy.com... > In article <3alo9bF6d2vo8U1@individual.net>, > Robert Klemme wrote: >> >> >>I'm surprised about "retry", too. His analysis sounds all very >>resonable - >>only that "break" does not work for me but "return" does: >> >>>> def my_while(cond) >>>> break unless cond >>>> yield >>>> retry >>>> end >>=> nil >>>> i = 0 >>=> 0 >>>> my_while i < 10 do >>?> puts i >>>> i += 1 >>>> end >>0 >>1 >>2 >>3 >>4 >>5 >>6 >>7 >>8 >>9 >>LocalJumpError: unexpected break >> from (irb):2:in `my_while' >> from (irb):7 > > > Hmmm... break works find for me in 1.8.2. Time to upgrade? Yeah, maybe. >>Btw, can anybody think of a way to make my_while return the result of the >>last block evaluation? It seems impossible because the return occurs >>before >>the yield... >> > > > How about: > > def my_while(cond) > return @ret unless cond > @ret = yield > retry > end Not thread safe. And I think also not nesting safe. Cheers robert