A brief forward on character sets is necessary. I don't think Thing1
should say *anything* other than that chars exist and may not be
isomorphic to the set of exact whole numbers less than 255. All the
Unicode magic can easily be in Thing2.

Given the above assumption, this is, IMNSHO, the minimal set of IO
functions needed. And while I expect people to thoroughly hate it, I
hope the semantics are relatively obvious:

(make-port name . options) ;=> port (and yes the options parameter
avoids handwaving about input/output/append/etc modes)

(read-octet . port)      ;=> u8
(read-char . port)       ;=> char, may raise an error if called at an
invalid char boundary caused by reading octets
(read-line . port)        ; string, may raise an error if called at an
invalid char boundary caused by reading octets

(write-octet u8 . port)   ;=> unspecified
(write-char char . port) ;=> unspecified
(write-line string . port) ;=> unspecified

; and here's the kicker, where the semantics are a little funky
(string->datum string k-success k-more k-error) ;=> datum

for each call to string->datum, exactly one of k-success, k-more or
k-error is called depending on the state of the parse. The
kontinuation functions will be called as follows:

(k-success datum remaining-string)
(k-more parser-continuation)
(k-error error-symbol error-continuation parsed-string remaining-string)

The parser-continuation function has the same signature as
string->datum, but it may be (and probably is!) a closure captured
from within the original parse. The error-continuation function allows
the programmer to recover from deviations in parsing a standard datum
by inserting a datum into the current parse and restarting it with the
following signature:

(error-continuation datum string k-success k-more k-error) ;=> datum

This gives us char encoding independence in the standard IO, run-time
extensibility for reading new data types, and useful binary I/O. I
think it's a win and *way* less complicated than most other IO
proposals (some of which I have propagated over the years)

david
-- 
GPG Public key at http://cyber-rush.org/drr/gpg-public-key.txt

_______________________________________________
r6rs-discuss mailing list
[email protected]
http://lists.r6rs.org/cgi-bin/mailman/listinfo/r6rs-discuss

Reply via email to