[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

(r6rs io ports)

From: Mike Gran
Subject: (r6rs io ports)
Date: Sun, 4 Apr 2010 12:24:18 -0700 (PDT)


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

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.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]