On Tue, 22 Aug 2000, Dave Thomas wrote:

> Well, I can't speak to the reason, but I can suggest why it might not
> be a Good Thing.
> 
> Firstly, Ruby does allow
> 
>   for a,b,c in [[1,2,3],[4,5,6]]
> 
> The 'for' iterates over the elements in the list, which are
> themselves arrays. The assignment of the array to the for loop
> variables is then done in parallel.

I only tried it with a flat array, so I didn't spot the case Guy Decoux
mentioned, either..

> 
> So, why not allow the assignment to pull values from a linear array?
> 
> Two possible reasons:
> 
> 1. It would be a special case, inconsistent with the semantics of
>    assignment elsewhere. Remember that the for loop actually becomes
>    (effectively)
> 
>       for i in list  =>  list.each do |i|
> 
>    So a for loop with multiple parameters is
> 
>       for i,j,k in list  =>  list.each do |i,j,k|
> 
>    The iterator would have to change it's behavior depending on the
>    block parameter count, which would be weird.

Well, it would only pull off as many as it needed.  I'm not sure that
this is particularly wierd, but it is harder to implement for user
classes, so maybe people would dislike having to achieve such consistency.

> 
> 2. It isn't very good OO style. This one is trickier. What you're
>    coding up top is an array where every fifth element is a parameter, 
>    every fifth element plus one is another parameter, etc.
> 
>    Wouldn't it be more natural to have a class which represented an
>    individual test?
> 
>      class TestStuff
>         def initialize(p1, p2, p3, res1, res2)
>           #...
>         end
>      end
> 
> 
>     tests = [
>        TestStuff.new(1, 2, 3, 4, 5),
>        TestStuff.new(5, 6, 7, 8, 9)
>     ];
> 
>    for t in tests
	[...]
>    end

Yes, this is a lot better.  I keep forgetting that one can use an
object *just* as a struct!
> 
> 
>    You could then extend it further. TestStuff could 'know' about
>    My_class,
> 
>    class TestStuff
>         def initialize(p1, p2, p3, res1, res2)
>           #...
>         end
>         def runTest
	     [...]
>         end
>      end
> 
>    And the loop would be
> 
>    tests.each {|t| t.runTest}

That is neater still. Thank you.
> 
> 
>    However, whether this is appropriate depends on the structure of
>    your application.
> 
I think it is appropriate for the for loop case I mentioned. Thank you.

> 
> Regards
> 
> 
> Dave
>     
I think you have convinced me that there is no real reason to ask for
this change, since "There's A Better Way To Do It" than I thought.

	Thank you,
	Hugh
	hgs / dmu.ac.uk