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.
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
(see section `Input' in The Revised^4 Report on Scheme) 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#\space45d10#\>
Go to the first, previous, next, last section, table of contents.