series (was: streams (was: reiter)))

Beni Cherniavsky cben@techunix.technion.ac.il
Sun, 10 Aug 2003 21:45:41 +0300 (IDT)


Beni Cherniavsky wrote on 2003-08-10:

> Thus I'm releasing the module under yet another name:
>
>     http://www.technion.ac.il/~cben/python/series.py
>
> I'd like to stop the renamings at this stage, so if you don't like it,
> speak now :-).
>
[Sorry, hit Send too soon...]  Here is the summary of what this is:

This module exposes the duality between linked lists and iterators:

- Simple linked lists have the drawback that their tail must be known
  and finite.  This can be fixed by overloading head/tail access and
  making it lazy; the result is popular in functional programming
  languages [1]_.  This is implemented by the `Series` and
  `UncomputedSeries` classes.

- Iterators have the drawback that advancing them is destructive but
  there is no way to capture the ''remaining future'' of an iterator
  at some moment. This can be fixed by making an iterator explicitly
  point to a series and allow separate iterators to be forked from it.
  This is implemented by the `SeriesIter` class.

Another useful thing about linked lists is that you can
non-destructively cons items in front of them.  This is implemented by
the `Series` class (which is also used to represent the part of series
that has already been computed) and is also accessible through the
`SeriesIter.unyield()` method.

A convenince subscripting interface is provided for series.

-- 
Beni Cherniavsky <cben@tx.technion.ac.il>