Programming Language for Old Timers


by David A. Moon
February 2006 .. September 2008

Comments and criticisms to dave underscore moon atsign alum dot mit dot edu.


Previous page   Table of Contents   Next page


Stream Protocol

A stream is a stateful object that effectively combines a sequence and an iteration state for that sequence. Unlike iterating through a sequence, iterating through a stream changes the stream.

The following method requirements constitute the stream protocol:

defprotocol stream
  end?(x is stream) is boolean
  next(x is stream)             ; returns next element
  advance(x is stream)
Their behavior is very similar to the methods of the same names of the sequence protocol. There is no start-iteration method, as this happens automatically when a stream is created. The advance method does not return anything in particular.

There is a pseudo-constructor method stream that takes a sequence and returns a stream that iterates through that sequence.


Previous page   Table of Contents   Next page