From: Robert Klemme on
2010/6/1 botp <botpena(a)gmail.com>:
> On Mon, May 31, 2010 at 9:53 PM, Robert Klemme
> <shortcutter(a)googlemail.com> wrote:
>> Because it is closer on what OP initially did:
>
> LOL. ok i get it :)
> i was just pointing out how to retrieve the index (and the relevance
> of it). i wouldn't want to "give" him *the* answer because i think
> rubyist _are_ programmers...
>
> kind regards -botp
>
>> irb(main):001:0> [5, 7].each_with_index.each {|*a| p a}
>> [5, 0]
>> [7, 1]
>> => [5, 7]
>
> or simply,
>
> => [5, 7].each_with_index{|*a| p a}
> [5, 0]
> [7, 1]
> => [5, 7]

No, this does not create an intermediate Enumerator. For trying to
hunt down a potential bug this does not help because it leaves the
Enumerator creation totally out of the loop.

>> This means that in your code the index cannot get lost along the way
>> simply because it is added in the last step and not in the initial
>> step.
>
> shouldn't the programmer be the judge for that?
>
> eg, i can easily scale if i need the square and the index...
>
>> [5, 7].map{|a| a*a }.each_with_index{|*a| p a}
> [25, 0]
> [49, 1]

I think we are talking past each other. IMHO this thread is about a
potential bug and you are talking about a solution with regard to
getting an index while iterating.

Cheers

robert

--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/

From: botp on
On Tue, Jun 1, 2010 at 4:14 PM, Robert Klemme
<shortcutter(a)googlemail.com> wrote:
> I think we are talking past each other.

no. it's me who is talking past. you're right on really :)

>  IMHO this thread is about a potential bug

indeed. sorry for the noise. arggh.
best regards -botp

> Cheers
> robert

From: Robert Dober on
I am afraid that is incorrect :(
ruby -ve '[5, 7].each_with_index.each {|a| p a}'
ruby 1.9.2dev (2010-05-31 revision 28117) [i686-linux]
5
7



--
The best way to predict the future is to invent it.
-- Alan Kay

From: botp on
On Tue, Jun 1, 2010 at 11:04 PM, Robert Dober <robert.dober(a)gmail.com> wrote:
> ruby -ve '[5, 7].each_with_index.each {|a| p a}'
--> |*a|

From: Robert Dober on
On Tue, Jun 1, 2010 at 5:12 PM, botp <botpena(a)gmail.com> wrote:
> On Tue, Jun 1, 2010 at 11:04 PM, Robert Dober <robert.dober(a)gmail.com> wrote:
>> ruby -ve '[5, 7].each_with_index.each {|a| p a}'
>                                                   -->  |*a|
>
>
I am afraid you lost us again, the bug is that the information is lost
when the splash is *not* added, e.g. with 1.9.1

ruby -ve '[5, 7].each_with_index.each {|*a| p a}'
ruby 1.9.1p378 (2010-01-10 revision 26273) [i686-linux]
[5, 0]
[7, 1]

515/14 > ruby -ve '[5, 7].each_with_index.each {|a| p a}'
ruby 1.9.1p378 (2010-01-10 revision 26273) [i686-linux]
5
7

But I admit this one is tricky to follow in such a long thread ;)
Cheers
R.



--
The best way to predict the future is to invent it.
-- Alan Kay