Subject: Re: my scheme os...
From: rpw3@rigden.engr.sgi.com (Rob Warnock)
Date: 8 May 2002 09:16:41 GMT
Newsgroups: comp.lang.scheme
Message-ID: <abaqdp$11jh6j$1@fido.engr.sgi.com>
Alex Shinn  <foof@synthcode.com> wrote:
+---------------
| This is similar to Guile's soft ports, which lets you define ports as a
| vector of procedures to use for reading/writing characters and strings.
| With this definition you can define a procedural port that performs
| whatever filter action you want...
...
| This seems like a very simple but useful feature - do any other schemes
| offer this ability?
+---------------

MzScheme does. It calls them "custom ports":

    <URL:http://www.cs.rice.edu/CS/PLT/packages/doc/mzscheme/node123.htm>
    The make-input-port and make-output-port procedures create ports with
    arbitrary control procedures:
        (make-input-port read-char-proc char-ready?-proc close-proc
	                 [peek-char-proc]) creates an input port. 
    ...
        (make-output-port write-proc close-proc) creates an output port.
    ...
    Ports created by make-input-port and make-output-port are immediately
    open for reading or writing. If the close procedure does not have any
    side-effects, then the custom port does not need to be explicitly closed. 

If you don't need to get control on *every* character, MzScheme also
provides "string ports":

    <URL:http://www.cs.rice.edu/CS/PLT/packages/doc/mzscheme/node121.htm>
    Scheme input and output can be read from or collected into a string:
	(open-input-string string) creates an input port that reads
		characters from string.
	(open-output-string) creates an output port that accumulates
		the output into a string.
	(get-output-string string-output-port) returns the string
		accumulated in string-output-port. 
    ...


-Rob

-----
Rob Warnock, 30-3-510		<rpw3@sgi.com>
SGI Network Engineering		<http://reality.sgiweb.org/rpw3/>
1600 Amphitheatre Pkwy.		Phone: 650-933-1673
Mountain View, CA  94043	PP-ASEL-IA

[Note: aaanalyst@sgi.com and zedwatch@sgi.com aren't for humans ]