Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

A suggestion for a new closure trait.

1 view
Skip to first unread message

Joe Gottman

unread,
Aug 29, 2006, 9:21:08 PM8/29/06
to Perl6 Language List
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


Jonathan Lang

unread,
Aug 30, 2006, 2:25:07 AM8/30/06
to perl6language,
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

Sage La Torra

unread,
Aug 30, 2006, 2:49:24 AM8/30/06
to perl6language,


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

Sage

0 new messages