Mark (>), Carl (>>):
> <Yobert> Hey do you know what would be cool in perl 6
> <Yobert> A special variable for when you do a for (@array) style loop
> <Yobert> it would always have the index of the array
>
> Discussed on #perl6: it's already quite easy in Perl 6 to loop with an
> explicit index:
>
> my @array = <moose elk caribou>;
> for @array.kv -> $i, $val {
> say "$i\t$val";
> }
>
> But maybe a variable that implicitly carries along the loop index
> would be even snazzier?
Whatever is done should also work for grep and map.
Oh, definitely.
In fact, you may just have found the raison d'etre for this feature. I
suppose doing a map or a grep over @array.kv is possible:
pugs> my @array = <london bridge is falling down>
("london", "bridge", "is", "falling", "down")
pugs> map { "Element $^a is called $^b" }: @array.kv;
("Element 0 is called london",
"Element 1 is called bridge",
"Element 2 is called is",
"Element 3 is called falling",
"Element 4 is called down")
But it can hardly be blamed for clarity.
--
masak