Re: LangSpec: Statements and Blocks [first,last]
iVAN wrote: > As we read in Damian Conway- Perl6-notes, there will be "...may be..." (Remember, I'm only the shambling henchman ;-) > a var-iterator that can be used to see how many times the cycle has > been "traversed" i.e. > > foreach my $el (@ary) { >.. do something > print $#; <--- print the index (or print $i ) > } Current thinking is that this functionality may be better provided by bestowing it on a lexical via a property/trait: foreach my $el (@ary) { my $i: index; ... print $i; } This seems preferable since it avoids reintroducing a punctuation variable and allows nested loop counters to work consistently: foreach my $el (@ary) { my $i: index; for my $el2 (@ary2) { my $j : index; @table[$i][$j] = $el * $el2; } } > shall we have : > > foreach my $el (@ary) { > print $# if $#.first(); >.. do something > print $# if $#.last(); > i.e. $#ary > }; I very much doubt it. Damian
Re: LangSpec: Statements and Blocks [first,last]
On Sunday 02 September 2001 06:27 pm, raptor wrote: > ]- yep I didn't thougth about that I can be sure I'm at the last > iteration only with some sort of 'callback' which will be called at the > exit of the loop... but not as some sort of generalised-check condition.. Umm, it's simpler than that. iterator (list) { code; } # <- If you are here, you just completed your last iteration. # (Unless you goto'd somewhere else, obviously. But that would # skip the callback, too.) -- Bryan C. Warnock [EMAIL PROTECTED]
Re: LangSpec: Statements and Blocks [first,last]
| I don't know if (and if so, how) you would see if you were on the last | iteration. (And would that be last, as in the very last argument passed in, | or last, as in you're not going to iterate again?) ]- yep I didn't thougth about that I can be sure I'm at the last iteration only with some sort of 'callback' which will be called at the exit of the loop... but not as some sort of generalised-check condition.. = iVAN [EMAIL PROTECTED] =
RE: LangSpec: Statements and Blocks [first,last]
> -Original Message- > From: raptor [mailto:[EMAIL PROTECTED]] > Sent: Sunday, September 02, 2001 1:47 PM > To: [EMAIL PROTECTED] > Cc: [EMAIL PROTECTED] > Subject: Re: LangSpec: Statements and Blocks [first,last] > > > hi, > > As we read in Damian Conway- Perl6-notes, there will by a > var-iterator that > can be used to see how many times the cycle has been "traversed" i.e. > > foreach my $el (@ary) { >.. do something > print $#; <--- print the index (or print $i ) > } > > shall we have : > > foreach my $el (@ary) { > print $# if $#.first(); <--- print the index on the first iteration I personally don't like the .first() .last() method implementation, this means we'll have .second .third, etc... Why not just check the var iterator $# == 0, means the first iteration, or have a special var that is not set to the index, but rather the iteration number 1..end, in case the there is a way to start iteration at different points. Ilya > i.e. 1 >.. do something > print $# if $#.last(); <--- print the index on the first iteration > i.e. $#ary > }; > > note : we can iterate on something else not only array > OR : > > foreach my $el (@ary) { > print $# if first; >.. do something > print $# if latest; > }; > > > = > iVAN > [EMAIL PROTECTED] > = > PS. One place where TT is before Perl :") >
Re: LangSpec: Statements and Blocks [first,last]
On Sunday 02 September 2001 01:47 pm, raptor wrote: > As we read in Damian Conway- Perl6-notes, there will by a var-iterator > that can be used to see how many times the cycle has been "traversed" i.e. > > foreach my $el (@ary) { >.. do something > print $#; <--- print the index (or print $i ) > } > > shall we have : > > foreach my $el (@ary) { > print $# if $#.first(); <--- print the index on the first iteration I think it's just a simple counter. print $# if $# == 0; > i.e. 1 0 >.. do something > print $# if $#.last(); <--- print the index on the first iteration I don't know if (and if so, how) you would see if you were on the last iteration. (And would that be last, as in the very last argument passed in, or last, as in you're not going to iterate again?) -- Bryan C. Warnock [EMAIL PROTECTED]
Re: LangSpec: Statements and Blocks [first,last]
hi, As we read in Damian Conway- Perl6-notes, there will by a var-iterator that can be used to see how many times the cycle has been "traversed" i.e. foreach my $el (@ary) { .. do something print $#; <--- print the index (or print $i ) } shall we have : foreach my $el (@ary) { print $# if $#.first(); <--- print the index on the first iteration i.e. 1 .. do something print $# if $#.last(); <--- print the index on the first iteration i.e. $#ary }; note : we can iterate on something else not only array OR : foreach my $el (@ary) { print $# if first; .. do something print $# if latest; }; = iVAN [EMAIL PROTECTED] = PS. One place where TT is before Perl :")