Rod Adams <[EMAIL PROTECTED]> writes:

> One solution I see to this would be to have a "lazy return" of some
> kind, where you can send out what results you have so far, but not
> commit that your execution is over and still allow further results to
> be posted. For lack of better word coming to mind, I'll call a "lazy
> return" C<emit>.
>
> Example above becomes:
>
> sub MediansBy5 ([EMAIL PROTECTED]) {
>   while @list.length >= 5 {
>     emit (sort @list.splice(0,5))[2];
>   }}

That has a certain elegance.

It is worth noting that emit is shorter than return, so people are
going to be tempted to use it when they don't really need the
laziness.  Obviously it won't be a full substitute for return because
by definition it doesn't have the (often desirable) side-effect of
terminating the current function.  But I can see people writing things
like this...

sub foo (some arguments) {
  do_stuff();
  emit some value(s);
}

At the right brace there there is (if I understand correctly what
hasn't changed from Perl5) an implicit return, which returns the value
of the last evaluated thing in the block, which in this case would be
the emit.  So, a couple of questions:

 1.  What if anything do you propose is the evaluation value of emit?
 2.  Should a subsequent implicit return behave differently than usual
     if some values have already been emitted?

If the answer to question 1 is a more-or-less nonexistant value, then
question 2 might lose its importance.

One other question:  Would emit behave differently if the sub is
called in a non-list context, such as void context or a scalar
context?

-- 
$;=sub{$/};@;=map{my($a,$b)=($_,$;);$;=sub{$a.$b->()}}
split//,"[EMAIL PROTECTED]/ --";$\=$ ;-> ();print$/

Reply via email to