On Mon, Feb 02, 2009 at 07:47:33PM -0300, Daniel Ruoso wrote:
: Em Seg, 2009-02-02 às 09:37 -0800, Larry Wall escreveu:
: > It's also not clear how this should interact with buffering systems
: > like stdio. But in any case, speaking directly to the IO stack is
: > likelier to give consistent results than playing mix-n-match with
: > various calls on the IO stack that make various assumptions.
:
: The question here is, will Perl 6 IO use stdio.h or re-implement its
: features?
Well, I think we need to think about IO in terms of the iterator
model of laziness, where we've defined semi-laziness to be more
or less what stdio buffering does: work ahead as necessary for
efficiency.
: My first shot at it would be...
:
: role IO {
: has $.fd;
: }
:
: role IO::Blocking {
: has Bool $.blocking;
: }
:
: role IO::Closeable {
: method close {...}
: }
:
: role IO::Readable {
: # no buffer
: method int read($buf is rw, int $count) {...}
: }
:
: role IO::Writeable {
: # no buffer
: method int write($buf, int $count) {...}
: }
:
: role IO::Buffered {
: # buffer
: has Bool $.autoflush is rw;
: method flush {...}
: }
:
: role IO::Char does IO::Buffered {
: method getc {...}
: method fread {...}
: ...
: }
Roles are good, but what is this Char thing of which you speak? It
seems good neither for Unicode characters nor for keystroke sequences. :)
On this non-blocking keystroke thing, I see a P6ish solution more like:
get_keystrokes() ==>> my @available;
# time passes
if @available { ... }
That is, use the async capabilities already built into the language.
(That's assuming the boolean value of @available doesn't block on the
state of the feed. If it does, we need some other way of expressing
that test. @available.now or some such.)
Larry