Ingo Blechschmidt skribis 2005-11-20 16:44 (+0100):
> Where is the difference (for the user) between a subroutine which
> returns an appropriate proxy object and an array?

An object is a scalar, an array is an array. Perl has unreferenced
arrays --I like to call them "pure" arrays--, and references to arrays.

A sub can, as far as I know, return a pure array, if the sub is an
lvalue sub. The array that is returned can be tied to be a reversed view
of the original array.

The big difference between pure arrays and referenced arrays, for the
user, is that pure arrays flatten in list context, while referenced
arrays do not. Especially with for, this is very relevant.

I don't know if it is possible for an object to flatten in list context,
but I would be surprised if it turned out to be. Scalars should NEVER
flatten in list context. This includes all references and thus objects.

> I think it'd even optimize many cases:
>     for @foo ¥ @bar {...}

All for-optimizations are in the for, in Perl 5. It would be nice to
have these in the actual functions and operators in Perl 6. Then
for-reverse is not a special case anymore, and the optimization is
indeed optimizing other cases too.

> (BTW, IIUC, per r6622 of S06.pod [1] &zip returns an array of arrayrefs
> now:
>     for zip('a'...; 0...; @foo) -> [$a, $i, $x] { ...}

Hm, that's sufficiently ugly. Is this really needed?

I quite like how

    for @foos Y @bars -> $foo, $bar { ... }

looks, and don't quite like

    for @foos Y @bars -> [ $foo, $bar ] { ... }

as much.

> (Or does for no longer automatically take as much elements from the
> input array as needed?

I like the arity-sensitivity solution better, I think.


Juerd
-- 
http://convolution.nl/maak_juerd_blij.html
http://convolution.nl/make_juerd_happy.html 
http://convolution.nl/gajigu_juerd_n.html

Reply via email to