unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* (r6rs io ports)
@ 2010-04-04 19:24 Mike Gran
  2010-04-05 15:16 ` Andy Wingo
  2010-04-10 11:06 ` Ludovic Courtès
  0 siblings, 2 replies; 11+ messages in thread
From: Mike Gran @ 2010-04-04 19:24 UTC (permalink / raw)
  To: guile-devel

Hi-

I've been thinking about the (r6rs io ports) module.  It is a fairly big
undertaking, but, the challenges are similar to the Unicode update to
the current port system.

First, let me note the ways that r6rs ports and Guile legacy ports are
different:

1.  Encoding is a property of the port vs a property of a transcoder

    R6RS have transcoder objects that describe a conversion as well
    as the state of the conversion.  These can be attached to ports
    or removed from ports.

2.  Pushback vs lookahead

    Guile legacy ports implement an ungetc operation.  You can
    always push a character back onto a port, even if the underlying
    port doesn't support it.  It does this by implementing a
    pushback buffer for each port.  Characters that are 'ungotten'
    go into the pushback buffer, and the next getc checks the
    pushback buffer first.  The pushback code is rather complex.

    This behaviour is vital to operation of the legacy Guile parser,
    which uses 'ungetc' repeatedly.

    (I suppose this would allow Guile to parse code from a pipe,
    but, I've never tried that.)

    R6RS ports instead have the concept of 'lookahead' but no
    'ungetc'.  Characters can not be pushed back onto a port, but,
    one can lookahead to see what bytes or characters are next.

Anyway.  On to implementation...

There are 4 types of R6RS ports: file, bytevector, string, and custom.
Each port is either binary or textual, and not both at the same time.

So one possibility is the following....

1. Expose scheme functions that are a set of low level file operations
that bypass Guile legacy ports and scm_getc.

2. Build the binary R6RS port system in Scheme using these functions,
and the bytevector and string functions that already exist.

(There will be no pushback buffer or intermediate storage of port data.
If a file supports random access or rewind, the lookahead operation will
succeed.  Otherwise, it will fail.)

3. Create a transcoder object in C that holds encoding and conversion
strategies, similar to those that we have attached to Guile legacy
ports.  Add methods to the transcoder object to do conversion between
bytevectors and strings.

4. Build textual R6RS ports in Scheme on top of the binary R6RS port 
system and the transcoder object.

5. And, ultimately, create a 'pushback buffer' object that supports
an ungetc operation.  Rebuild Guile legacy ports as a combination 
of R6RS ports and a pushback buffer object.

-Mike





^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2010-04-11 23:01 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-04-04 19:24 (r6rs io ports) Mike Gran
2010-04-05 15:16 ` Andy Wingo
2010-04-10 11:06 ` Ludovic Courtès
2010-04-10 16:49   ` Mike Gran
2010-04-10 18:14     ` Ludovic Courtès
2010-04-10 19:03       ` Mike Gran
2010-04-10 19:45         ` Ludovic Courtès
2010-04-11 23:01           ` Mike Gran
2010-04-11 21:38         ` Andy Wingo
2010-04-11  3:34       ` Julian Graham
2010-04-11 21:40         ` Andy Wingo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).