[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ] Input utility functions

Function: port->string port
Function: port->list reader port
Function: port->string-list port
Function: port->sexp-list port
Generally useful input procedures. The API is taken from scsh and STk.

port->string reads port until EOF and returns the accumulated data as a string.

port->list applies reader on port repeatedly, until reader returns an EOF, then returns the list of objects reader returned.

(port->string-list port) == (port->list read-line port) , and (port->sexp-list port) == (port->list read port) .

Function: port-fold fn knil reader
Function: port-fold-right fn knil reader
Function: port-for-each fn reader
Function: port-map fn reader
Convenient iterators over the input read by reader. Basically, reader is called repeatedly without arguments and fn is called for each item it returns, until reader returns EOF. Actually reader can be any thunk; it doesn't need to be related to input port.

Suppose reader returns a series of items {X0, X1, ..., Xn}. port-fold returns the following:
(fn Xn (fn Xn-1 ... (fn X0 knil)))
while port-fold-right returns the following:
(fn X0 (fn X1 ... (fn Xn knil)))
That is, (port-fold cons '() read) returns a reverse list of all the inputs, while (port-fold-right cons '() read) returns the same thing as (port->list read port).

On the other hand, port-for-each and port-map applies fn to each item. The former discards the results fn returns, while the latter returns a list of results.

This document was generated by Ken Dickey on November, 28 2002 using texi2html