(guile.info.gz) Soft Ports
Info Catalog
(guile.info.gz) String Ports
(guile.info.gz) Port Types
(guile.info.gz) Void Ports
27.9.3 Soft Ports
-----------------
A "soft-port" is a port based on a vector of procedures capable of
accepting or delivering characters. It allows emulation of I/O ports.
-- Scheme Procedure: make-soft-port pv modes
-- C Function: scm_make_soft_port (pv, modes)
Return a port capable of receiving or delivering characters as
specified by the MODES string ( open-file File Ports.). PV
must be a vector of length 5. Its components are as follows:
0. procedure accepting one character for output
1. procedure accepting a string for output
2. thunk for flushing output
3. thunk for getting one character
4. thunk for closing port (not by garbage collection)
For an output-only port only elements 0, 1, 2, and 4 need be
procedures. For an input-only port only elements 3 and 4 need be
procedures. Thunks 2 and 4 can instead be `#f' if there is no
useful operation for them to perform.
If thunk 3 returns `#f' or an `eof-object' ( eof-object?
(r5rs)Input.) it indicates that the port has reached end-of-file.
For example:
(define stdout (current-output-port))
(define p (make-soft-port
(vector
(lambda (c) (write c stdout))
(lambda (s) (display s stdout))
(lambda () (display "." stdout))
(lambda () (char-upcase (read-char)))
(lambda () (display "@" stdout)))
"rw"))
(write p p) => #<input-output: soft 8081e20>
Info Catalog
(guile.info.gz) String Ports
(guile.info.gz) Port Types
(guile.info.gz) Void Ports
automatically generated byinfo2html