Next Previous Up Top Contents Index

5.11 The STREAMS module

read-element

Open generic function

Summary

Reads the next element in a stream.

Signature

read-element input-stream #key on-end-of-stream 
=> element-or-eof

Arguments

input-stream
An instance of <stream>.

on-end-of-stream
An instance of <object>.

Values

element-or-eof
An instance of <object>.

Library

io

Module

streams

Description

Returns the next element in the stream. If the stream is not at its end, the stream is advanced so that the next call to read-element returns the next element along in input-stream.

The on-end-of-stream keyword allows you to specify a value to be returned if the stream is at its end. If the stream is at its end and no value was supplied for on-end-of-stream, read-element signals an <end-of-stream-error> condition.

If no input is available and the stream is not at its end, read-element waits until input becomes available.

Example

The following piece of code applies function to all the elements of a sequence:

let stream = make(<sequence-stream>, contents: seq);
while (~stream-at-end?(stream)) 
  function(read-element(stream));
end;

See also

<end-of-stream-error>, page 67

peek, page 81

unread-element, page 58


System and I/O Reference - 31 MAR 2000

Next Previous Up Top Contents Index