From: Mike Gran <spk121@yahoo.com>
To: guile-devel <guile-devel@gnu.org>
Subject: (r6rs io ports)
Date: Sun, 4 Apr 2010 12:24:18 -0700 (PDT) [thread overview]
Message-ID: <784638.41402.qm@web37907.mail.mud.yahoo.com> (raw)
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
next reply other threads:[~2010-04-04 19:24 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-04-04 19:24 Mike Gran [this message]
2010-04-05 15:16 ` (r6rs io ports) 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=784638.41402.qm@web37907.mail.mud.yahoo.com \
--to=spk121@yahoo.com \
--cc=guile-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).