Next: , Previous: , Up: Streams   [Contents][Index]


6.3.5 Stream Functions

Some operations may be performed on any kind of stream; the following is a list of standardized operations that are potentially useful with any kind of stream.

Some General-Purpose Stream Operations

Function: close stream &key abort => result

close closes stream. Closing a stream means that it may no longer be used in input or output operations. The act of closing a file stream ends the association between the stream and its associated file; the transaction with the file system is terminated, and input/output may no longer be performed on the stream.

STREAM

a stream (either open or closed).

ABORT

a boolean with a ‘false’ default value. If abort is ‘true’, an attempt is made to clean up any side effects of having created stream. If stream performs output to a file that was created when the stream was created, the file is deleted and any previously existing file is not superseded.

Function: input-stream-p stream => boolean
Function: output-stream-p stream => boolean

input-stream-p returns ‘true’ if stream is an input stream; otherwise, returns ‘false’.

output-stream-p returns ‘true’ if stream is an output stream; otherwise, returns ‘false’.

Function: interactive-stream-p stream => boolean

Returns ‘true’ if stream is an interactive stream13; otherwise, returns ‘false’.

Function: stream-element-type stream => typespec

stream-element-type returns a type specifier that indicates the types of objects that may be read from or written to stream. Streams created by open have an element type restricted to integer or a subtype of type character.

Function: streamp object => boolean

Returns ‘true’ if object is of type stream; otherwise, returns ‘false’.

Function: with-open-stream (var stream) declaration* form* => results

with-open-stream performs a series of operations on stream, returns a value, and then closes the stream. Var is bound to the value of stream, and then forms are executed as an implicit progn.

VAR

a variable name; bound to stream.

STREAM

a form; evaluated to produce a stream. The stream has dynamic extent; its extent ends when the form is exited.

DECLARATION

a declare expression; not evaluated.

FORM

an implicit progn.

RESULTS

the values returned by the forms.

(with-open-stream (s (make-string-input-stream "1 2 3 4"))
    (+ (read s) (read s) (read s))) =>  6

Listing 6.1: Example of with-open-stream


Footnotes

(13)

A stream on which it makes sense to perform interactive querying. The general intent of having some streams be classified as interactive streams is to allow them to be distinguished from streams containing batch (or background or command-file) input. Output to batch streams is typically discarded or saved for later viewing, so interactive queries to such streams might not have the expected effect.


Next: Input Stream Functions, Previous: Reading Lines of a File using Standard Input, Up: Streams   [Contents][Index]