Next: , Previous: , Up: iklib io   [Index]


6.44.5 Additional textual port features

The following bindings are exported by the (vicare) library.

Parameter: current-input-port

As defined by R6RS: return a default textual port for input. Vicare extends its definition to allow selecting a new textual input port.

Parameter: current-output-port

As defined by R6RS: return a default textual port for output. Vicare extends its definition to allow selecting a new textual output port.

Parameter: current-error-port

As defined by R6RS: return a default textual port for error messages output. Vicare extends its definition to allow selecting a new textual output port.

Function: textual-input-port? obj
Function: textual-output-port? obj
Function: textual-input/output-port? obj

Return #t if obj is a textual port and, respectively, it is: input or input/output; output or input/output; input/output.

Function: textual-input-only-port? obj
Function: textual-output-only-port? obj

Return #t if obj is a textual port and, respectively, it is input–only or output–only.

Function: open-textual-port? obj
Function: open-textual-input-port? obj
Function: open-textual-output-port? obj
Function: open-textual-input/output-port? obj

Return #t if obj is an open textual port and, respectively, it is input, output or input/output.

Function: open-string-input-port string
Function: open-string-input-port string eol-style

As defined by R6RS: return a textual input port whose characters are drawn from string. When eol-style is given: it must be a symbol selecting an end–of–line style conversion, as accepted by eol-style; such conversion is applied to the characters drawn from string.

If string is modified after open-string-input-port has been called, the effect on the returned port is unspecified.

Function: open-string-input-port/id string id
Function: open-string-input-port/id string id eol-style

Like open-string-input-port but allows the specification of a customised port identifier id, which must be a Scheme string.

Function: open-string-output-port
Function: open-string-output-port eol-style

As defined by R6RS, return two values: a textual output port and an extraction procedure; the output port accumulates the characters written to it for later extraction by the procedure.

As a Vicare extension, when eol-style is given: it must be a symbol selecting an end–of–line style conversion, as accepted by eol-style; such conversion is applied to the characters written to the port.

Function: get-output-string port

Return the string accumulated in the port opened by open-string-output-port. This function can be called also when the port has been closed.

Function: get-char-and-track-textual-position port

Like get-char but track the textual position. Recognise only linefeed characters as line-ending.

Function: port-textual-position port

Given a textual port, return the current textual position as a condition object of type &source-position.

Function: make-textual-file-descriptor-input-port fd identifier transcoder
Function: make-textual-file-descriptor-output-port fd identifier transcoder
Function: make-textual-file-descriptor-input/output-port fd identifier transcoder

Build and return textual Scheme ports using the platform file descriptor fd as device. identifier must be a string used for better error reporting. transcoder must be a transcoder object. Closing the Scheme ports will close the file descriptors too.

File descriptor ports do support port position operations.

Function: make-textual-file-descriptor-input-port* fd identifier transcoder
Function: make-textual-file-descriptor-output-port* fd identifier transcoder
Function: make-textual-file-descriptor-input/output-port* fd identifier transcoder

Build and return textual Scheme ports using the platform file descriptor fd as device. identifier must be a string used for better error reporting. transcoder must be a transcoder object. Closing the Scheme ports will not close the file descriptors.

File descriptor ports do support port position operations.

Function: make-textual-socket-input/output-port sock identifier transcoder

Build and return a textual Scheme port using the platform socket descriptor sock as device. identifier must be a string used for better error reporting. transcoder must be a transcoder object. Closing the Scheme port will close the socket descriptor too.

Socket ports do not support port position operations.

Function: make-textual-socket-input/output-port* sock identifier transcoder

Build and return a textual Scheme port using the platform socket descriptor sock as device. identifier must be a string used for better error reporting. transcoder must be a transcoder object. Closing the Scheme port will not close the socket descriptor.

Socket ports do not support port position operations.

Function: read-line
Function: read-line port

Read from the textual input port up to and including the linefeed character or end of file, decoding characters in the same manner as get-string-n and get-string-n!. This function is exactly like get-line, defined by (rnrs io ports (6)), but it uses the return value of current-input-port if no port argument is used.

Function: get-string-some port

Defined by Vicare. Read from the textual input port, blocking as necessary, until characters are available or until an end of file is reached.

If characters become available, get-string-some returns a freshly allocated string containing the initial available characters (at least one), and it updates port to point just past these characters.

If no input characters are available: the EOF object is returned.

Function: with-input-from-string string thunk

thunk must be a procedure and it must accept zero arguments. string must be a Scheme string.

The string is used as argument for open-string-input-port; during the dynamic extent of the call to thunk, the obtained port is made the value returned by current-input-port; the previous default value is reinstated when the dynamic extent is exited.

When thunk returns, the port is closed automatically. The values returned by thunk are returned.

If, after thunk has returned, an escape procedure is used to reenter the dynamic extent of the call to thunk: the behaviour is unspecified.

Function: with-output-to-string thunk

Create a textual output port that accumulates the characters written to it, set it as the current output port and call thunk with no arguments. The port is the current output port only for the extent of the call to thunk.

Whenever thunk returns, a string consisting of all of the port’s accumulated characters (regardless of the port’s current position) is returned and the port is closed.


Next: , Previous: , Up: iklib io   [Index]