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

Re: A few random I/O proposals



On Wed, 27 May 92 15:58:01 EDT, "Andrew Wilcox" <andrew@astro.psu.edu> said:

> I would suggest adapting the idea of an output procedure used in Marc
> Feeley's genwrite.scm from SLIB to make a more general make-output-
> port procedure:

>      (make-output-port OUTPUT)

>      make-output-port returns an output port.  When an object is
>      written to the output port, OUTPUT is called one or more times
>      with one string argument, the successive substrings of the
>      textual transformation of the object.  OUTPUT may return #f to
>      stop the transformation.

> This way you can write open-output-string, open-truncated-output-
> string, or other procedures you want.

I don't really understand this.  Output ports should accept
characters, not arbitrary objects.  And they shouldn't really be able
to stop anything.  But I like the idea of being able to create a port
from a function - how about

(make-output-port WRITE-PROC CLOSE-PROC)

WRITE-PROC must be a procedure which takes a single argument, and
CLOSE-PROC must be a procedure which takes no arguments.
Make-output-port returns an output port.  When a character is written
to the output port, WRITE-PROC is called with that character as its
argument.  When the output port is closed, CLOSE-PROC is called with
no arguments.

Of course, there would also be a make-input-port, with WRITE-PROC
replaced by a READ-PROC of no arguments.

david carlton,
who also thinks that ports should be disjoint from other types