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

A few random I/O proposals (really: string ports)




++ String ports

> Before SchemeXerox switched over to the module system, we used what
> I think are the Chez Scheme names for these procedures:
> OPEN-INPUT-STRING, OPEN-OUTPUT-STRING, and GET-OUTPUT-STRING.  An
> important issue to resolve is the state of an output string port
> *after* a call to GET-OUTPUT-STRING.  Is it still open for use?  If
> so, is any new output appended onto the end of the string that
> GET-OUTPUT-STRING returned or is the port's contents reset to empty?
> In the latter case, what guarantees does one have about sharing
> between the returned string and the port's buffer if any?  Finally,
> what is the effect of my mutating the string given to
> OPEN-INPUT-STRING?  There are a number of reasonable sets of answers
> to these questions; if string ports are added to the report, some
> particular set of answers should be specified.

Let me take a try.  I did take a look at MacScheme, MIT Scheme, T,
Gambit, and Chez.

 (OPEN-INPUT-STRING <string>) -> <input-port>

 (OPEN-OUTPUT-STRING) -> <output-port>

 (GET-OUTPUT-STRING <output-string-port>) -> <mutable-string>

 (STRING-PORT? obj) -> <boolean>

String ports give the expected answers to INPUT-PORT? and
OUTPUT-PORT?.  Reading after the last character in an input string
port returns the eof-object.

GET-OUTPUT-STRING does reset the output string to a state which is
indistinguishable from that if the port was freshly bound with
OPEN-OUTPUT-STRING (as with Chez and Gambit, unlike MacScheme).  The
rationale for this is that [1] reset is undefined for other port
objects, [2] Pavel's questions above, [3] this is probably the most
desired behavior {when used}.  {My personal preference is that the
reset side effect be separate, but my guess is that there is more code
which would break if this strategy is followed--admittedly a weak
argument}.

The string returned by GET-OUTPUT-STRING is a new string, except that
all instances of the empty string are allowed to be shared (eqv?
rule).

If people make an argument that we need a FILE-INPUT-PORT? and
INTERACTIVE-INPUT-PORT?, etc. for symmetry, I would flush the
STRING-PORT? predicate.

Discussion?
-Ken