Re: A suggestion for a new closure trait.

2006-08-30 Thread Jonathan Lang

Joe Gottman wrote:

Since a FIRST block gets called at loop initialization time, it seems to me
that it would be useful to have a block closure trait, RESUME, that gets
called at the beginning of every loop iteration except the first. Thus, at
the beginning of each loop iteration either FIRST or RESUME but not both
would get called. Other possible names for this block include REENTER,
SUBSEQUENT, or NOTFIRST.


So RESUME would be to FIRST as NEXT is to LAST?

--
Jonathan Dataweaver Lang


Re: A suggestion for a new closure trait.

2006-08-30 Thread Sage La Torra

On 8/30/06, Jonathan Lang [EMAIL PROTECTED] wrote:


Joe Gottman wrote:
 Since a FIRST block gets called at loop initialization time, it seems to
me
 that it would be useful to have a block closure trait, RESUME, that gets
 called at the beginning of every loop iteration except the first. Thus,
at
 the beginning of each loop iteration either FIRST or RESUME but not both
 would get called. Other possible names for this block include REENTER,
 SUBSEQUENT, or NOTFIRST.

So RESUME would be to FIRST as NEXT is to LAST?



It's like the SATs all over again...

Sage


A suggestion for a new closure trait.

2006-08-29 Thread Joe Gottman
Since a FIRST block gets called at loop initialization time, it seems to me
that it would be useful to have a block closure trait, RESUME, that gets
called at the beginning of every loop iteration except the first. Thus, at
the beginning of each loop iteration either FIRST or RESUME but not both
would get called. Other possible names for this block include REENTER,
SUBSEQUENT, or NOTFIRST. 

RESUME would have many uses.  For example, to put commas in the right places
in a printed list:

for @list - @value {
print $value;
RESUME {print ', ';} #If this were NEXT we would print an extra comma at
the end.
LAST {print \n;}
}

RESUME could also be useful for maintaining state information, such as loop
iteration or running sum, between loop iterations:

for @data - $value {
   state $index will first {$_ = 0;} will resume {++$_;}
   state $sum will first {$_ = $value;} will resume {$_ += value;}
   ...
}


Joe Gottman