[Aldor-l] question about set! in streams / even shorter
Ralf Hemmecke
ralf at hemmecke.de
Thu Aug 24 15:19:30 EDT 2006
On 08/24/2006 08:56 PM, Martin Rubey wrote:
> Finally, I think I have the ultimate way to formulate my question:
>
> For a Stream, why does set! compute the element I want to modify destructively?
>
> Suppose I have a stream of the form s := stream(0, f) and I say
>
> set!(s, 0, 1783);
>
> why on earth is f(0) computed?
That is simple. Internally a stream is an Array(T) + a function
next: () -> T that computes the next element. If set! would not compute
f(0) (which means: call next() and store the value into the zeroth
position of the array), then the "next" function would be wrong since it
then is called for the first time to compute f(1), but remember, it is
called for the first time and so would assign to the array in position 1
what was actually meant for position 0.
> Is there a way around that? Unfortunately, the
> stream is already given. It is not an option to define it differently in the
> first place.
But you can define your own Stream. I more or less have already done so.
But I restrict to the stuff we need in aldor-combinat.
Ralf
More information about the Aldor-l
mailing list