Next: File Ports
Up: Ports
Previous: Pipes
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 port) returns the
string accumulated in the string output port port. (If port is
not a string output port, the exn:application:type exception is raised.)
String input and output ports do not need to be explicitly closed.
Example:
(define i (open-input-string "hello world"))
(define o (open-output-string))
(write (read i) o)
(get-output-string o) ; => "hello"
PLT