Re: ruby1.9 and the retry keyword



On Mon, Apr 20, 2009 at 02:10:33AM +0900, James Gray wrote:
On Apr 19, 2009, at 12:01 PM, Christopher Dicely wrote:

That mimics the example (where the retry is unconditional), but
clearly isn't a general solution;

I'll be surprised if more complex examples can't be similarly converted
fairly easily. That was kind of my point. I meant the code to say, take
a step back and think what is this trying to do?


My code walks an array, and may change the current element, which is allowed
without breaking the iteration.

I have also a special case where i have to change a whole subsection of the
array, this was the case where i used 'retry'

eg
ary.each { |e|
case e
when foo
ary[ary.index(e)] = foo(e)
when bar
when ...
when baz
ary[ary.index(e), 12] = [flublu]
retry
end
}

Sure, i could use map or many other ways, my code is quite ugly anyway.
I was just surprised by the change of behavior.

I don't see the point in removing capabilities from the language (restarting
an iteration from within), but I can sure live with it.

--
Yoann

.



Relevant Pages

  • Re: ruby1.9 and the retry keyword
    ... allowed without breaking the iteration. ... of the array, this was the case where i used 'retry' ... (restarting an iteration from within), but I can sure live with it. ...
    (comp.lang.ruby)
  • Re: Readline using foreach and while
    ... condition is checked at the start of each iteration, if the array ... map doesn't recheck the count ... the passed list for each iteration. ... @ary, which comes from a scope outside this sub, now contains (h, a, b, ...
    (comp.lang.perl.misc)
  • Re: Memory Leak Problem
    ... And each iteration I generated about 700000 random numbers. ... The variable that contains these random numbers is a pointer, ... compiler which does not allow REAL valued array indexes. ... to use rout, which has a pointer attribute, as an argument and then ...
    (comp.lang.fortran)
  • Re: Filter multi-dimensional array
    ... would fail to find all elements, but that the iteration order ... You have just become the first person to mention equivalence in this ... you can be sure that the array passed to your function contains ... the users of third-party libraries know that they are ...
    (comp.lang.javascript)
  • Re: Snapshot of List [Was: Re: sync on local variable]
    ... the iteration on the snapshot. ... it appears that an ArrayList is just an array ... How much extra machinery are we talking about, ...
    (comp.lang.java.programmer)