On Tue, Sep 20, 2005 at 14:47:33 -0400, Austin Frank wrote:
> Would the named adverbs for gather work in other contexts as well?
> Would you suggest this mechanism for specifying the buffering
> behavior for IO operations?

See scook's email below... I think that yes. Here is a reference
implementation making heavy use of coros:

        sub buffer_lazy ([EMAIL PROTECTED], +$threshold = 100) { # renamed 
scook's force_async
                my @buffer;

                state Sem $collecting;

                if ([EMAIL PROTECTED]) { # blocking
                        push @buffer, shift @lazy;

                if (@buffer.elems < $threshold and 
$collecting.lock(:nonblocking)) {
                        async {
                                LEAVE { $colecting.release };

                                while (@buffer.elems < $threshold) {
                                        push @buffer , shift @lazy; # or splice 
it splice returns a lazy list
                yield shift @buffer;

        my @lazy = buffer_lazy @other_lazy; # using @lazy should be more 

and where gather is

        sub gather (&body, +$async, +$threshold){
                my @result_list = {
                        temp sub *take ([EMAIL PROTECTED]) {
                                &OUTER::yield(@stuff); # how do we do this? 
                return $async
                        ?? buffer_lazy @result_list :threshold($threshold)
                        !! @result_list;

> Tim Bray recently wrote about wanting a language that would be
> smarter about IO buffering by default.  Will perl6 be such a
> language?

I think it already is about making life easy for the programmer. For
example, the 'will prompt' trait gives autoprompting to a read
handle, by making each read go to another handle, print, flush it
smartly for interactivity, and then actually read the data. This
makes the programmer's life less painful in many ways by
encapsulating a common problem in a standard library definition.

As for Tim's problem, I don't know what exactly Tim means, since I
don't know what he fixed in his program, but "I/O primitives are by
default bufferred unless the programmer specifically requested
otherwise" sounds a lot like perl 5 and $| ;-)

I think that Perl 6 needs more than this to be "smarter about IO
buffering", but I'm not sure I want it to be.

 ()  Yuval Kogman <[EMAIL PROTECTED]> 0xEBD27418  perl hacker &
 /\  kung foo master: /me beats up some cheese: neeyah!!!!!!!!!!!!!!!!!

Attachment: pgpmpQxyqj48w.pgp
Description: PGP signature

Reply via email to