Jonadab the Unsightly One writes:
> 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's actually a very good idea.  That's why Perl 6 has it :-)

    sub MediansBy5 ([EMAIL PROTECTED]) {
        gather {
            while @list >= 5 {   # there's no .length; it's .elems
            take (sort @list.splice(0,5))[2];
        }
    }

C<gather> returns a list of everything that was C<take>n inside of it.
It does this by building a coroutine out of its argument, so it works
lazily.

Luke

Reply via email to