Juerd wrote:
> Will Perl 6 support mutable for-reverse?

I'd like it! :)

> Some possible answers that I could think of:
> (a) Yes, but as a special case
> (b) Yes, because reverse returns lvalue aliases
> (c) No
> But there's another one, that I didn't immediately think of:
> (d) Yes, because reverse @foo always behaves like an array (rather
> than a function that *returns* a list), just with a different view:
> the elements are in the wrong order.

Where is the difference (for the user) between a subroutine which
returns an appropriate proxy object and an array?

  # Perl 5
  sub foo {...}
  foo[42];      # really foo([42])

  # Perl 6
  sub foo {...}
  foo[42];      # really (foo())[42]
  foo{"Pugs"};  # really (foo()){"Pugs"}
  foo<Pugs>;    # really (foo()){"Pugs"}

> This option d is interesting, and would probably be nice to have,
> because it would also allow this (contrived and useless) kind of
> thing:
>     push reverse(@foo), $bar;
> And while that isn't very interesting, I think something like
>     my @bar := reverse @foo;
> would be very useful.

Yep :)

(Also note that if we make &reverse return an appropriate proxy object
so this example works, for reverse @array {...} will automatically be

> The same thing would be interesting for zip:
>     my @xyzzy := @foo Y @bar;
> Assuming this results in an even number of elements in @xyzzy, pushing
> a single element onto @xyzzy could result in an element added to @foo
> every odd, and to @bar every even time.
> Would something like that be possible? Wanted?

I'd like that as well. (Generally, I'd like to see many lvalue subs and
methods in default Perl 6.)

> Not too costly?

I think it'd even optimize many cases:

    for @foo ¥ @bar {...}
    # Generating a new array containing @foo ¥ @bar is, thanks to
    # zip's laziness, unnecessary.

(BTW, IIUC, per r6622 of S06.pod [1] &zip returns an array of arrayrefs

    for zip('a'...; 0...; @foo) -> [$a, $i, $x] { ...}

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

    my @array = <a b c d>;
    for @array -> $a, $b { say "$a $b" }

no longer output "a b\nc d\n", but die?))


[1] http://svn.perl.org/perl6/doc/trunk/design/syn/S06.pod


Reply via email to