Re: RFC 120 (v2) Implicit counter in for statements, possibly $#.
[email protected] (Jonathan Scott Duff) Fri, 18 Aug 2000 10:01:35 -0500
| Newsgroups | perl.perl6.language.flow |
|---|---|
| Message-ID | <[email protected]> |
On Fri, Aug 18, 2000 at 09:07:31AM -0500, Christopher J. Madsen wrote:
[ Very Good examples elided ]
> With the explicit counter,
>
> foreach $item $index (@array) { ... }
>
> $index could (and should) be a read-only variable (like $i is in
> "foreach $i (1,2,3,4)"). This would make sure that it really was the
> index it claimed to be.
Excellent summary of why an explicit index is a Good Thing as compared
to the programmer doing it himself. I think the syntax would need to
be different though, how do you use implicit $_ and an index? (Don't
Do That is not an answer because people will want it) Here are some
ideas:
# Gosh, let's overuse : like python! ;-)
for $item:$index (@array) { ... }
for :$index (@array) { ... } # $_ and counter
for (@array : index($index)) { ... }
for (@array) $index { ... }
-Scott
--
Jonathan Scott Duff
[email protected]