Consider a slice @A[3,4,5,6,7]. That could be written @A[3..7] instead, and if you consider @A[3..50] that's a good thing.

Well, what about @A[7,6,5,4,3]? How would you write @A[50..3] to actually work?

I think that @A[reverse 3..50] should be sufficient, and that Perl6 will have support for open-ended lists so more exoitic generators can be created that don't force creation of the entire list ahead of time.

Replies are listed 'Best First'.
Re: .. in reverse
by mojotoad (Monsignor) on Aug 30, 2002 at 23:17 UTC
    ttaM

    .scitehtsea naht rehto eussi na fo hcum s'ti kniht t'nod I ?)syarra ton( stsil fo slasrever ezimitpo relipmoc lrep eht t'nseoD

    Doesn't the perl compiler optimize reversals of lists (not arrays)? I don't think it's much of an issue other than aesthetics.

    Matt

Re: .. in reverse
by BrowserUk (Patriarch) on Aug 31, 2002 at 00:53 UTC
      Of course they aren't always interchangable.... One can be used as an lvalue the other can't.
      #!/usr/bin/perl -wT use strict; my @a = 'a'..'f'; @a[reverse 5..10] = 'A'..'F'; # can you rewrite this line? print "@a\n"; __END__ a b c d e F E D C B A

      -Blake

        Yes! But It's not as pretty.

        #!/usr/bin/perl -w use strict; my @a = 'a'..'f'; #@a[reverse 5..10] = 'A'..'F'; # can you rewrite this line? splice @a, 5, 10-5, reverse ('A'..'F'); print "@a\n"; __END__ C:\test>194289.pl a b c d e F E D C B A

        Well It's better than the Abottoire, but Yorkshire!
        @a[reverse 5..10] = 'A'..'F';  # can you rewrite this line?
        @a[5..10] = reverse 'A'..'F';

        Not that it really addresses the point...

        -sauoq
        "My two cents aren't worth a dime.";