Stream programming

Nathan Rice nathan.alexander.rice at gmail.com
Fri Mar 23 17:33:35 CET 2012


> I will use "<=>" to mean "is equivalent to". That's not part of the DSL.
> A flow has one or more streams:
>  1 stream:
>    [1,2,3]
>  2 streams:
>    [1,3,5] | [2,4,6]
> Two flows can be concatenated:
>  [1,2,3] + [4,5,6] <=> [1,2,3,4,5,6]
>  [0] + ([1,2] | [3,4]) + [10] <=> [0,1,2,10] | [0,3,4,10]
>  ([1,2] | [10,20]) + ([3,4] | [30,40]) <=> [1,2,3,4] | [10,20,30,40]

Algebraically, your concatenation rules don't really make sense - your
flows are both distributive and non distributive.  You also make the
implicit assumption of an order over streams in a flow, but disregard
the implications of that assumption in some cases.  I understand what
you're trying to communicate, so I think you need to be a little more
strict and explicit in your definitions.

> A flow can be transformed:
>  [1,2] - f <=> [f(1),f(2)]
>  ([1,2] | [3,4]) - f <=> [f(1,3),f(2,4)]
>  ([1,2] | [3,4]) - [f] <=> [f(1),f(2)] | [f(3),f(4)]
>  ([1,2] | [3,4]) - [f,g] <=> [f(1),f(2)] | [g(3),g(4)]
>  [1,2] - [f,g] <=> [f(1),f(2)] | [g(1),g(2)]

Given the examples you pose here, it is clear that you are assuming
that the streams are synchronized in discrete time.  Since you do not
provide any mechanism for temporal alignment of streams you are also
assuming every stream will have an element at every time point, the
streams start at the same time and are of the same length.  Is this
what you want?  These seem like pretty rough simplifying assumptions.

> Some functions are special and almost any function can be made special:
>  [1,2,3,4,5] - filter(isprime) <=> [2,3,5]
>  [[],(1,2),[3,4,5]] - flatten <=> [1,2,3,4,5]
> Note that 'filter' is not really necessary, thanks to 'flatten'.

This implies that your transformations again produce flows.  You
should explicitly state this.

> Flows can be named, remembered and used
>  as a value:
>    [1,2,3,4,5] - 'flow' + val('flow') <=> [1,2,3,4,5]*2

Is this a flow with two identical streams, or a flow with one long
stream formed by concatenation?

>  as a transformation chain:
>    [1,2,3] - skipfirst - 'again' | [4,5,6] - func('again')
>      <=> [2,3] | [5,6]
>  Recursion is also possible and stops when a function is applied to an empty
> sequence.
> Flows can be saved (push) and restored (pop) :
>  [1,2,3,4] - push - by(2) - 'double' - pop | val('double')
>      <=> [1,2,3,4] | [2,4,6,8]
> There are easier ways to achieve the same result, of course:
>  [1,2,3,4] - [id, by(2)]

You are grasping at an algebra here, a sort of calculus of temporal
observations.  You need to step back and make it rigorous before you
worry about issues such as a readable syntax.

Nathan



More information about the Python-list mailing list