[Aldor-l] question about set! in streams / even shorter

Martin Rubey martin.rubey at univie.ac.at
Thu Aug 24 16:04:14 EDT 2006


Ralf Hemmecke <ralf at hemmecke.de> writes:

> 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.

Ah, that makes sense. That is, stream doesn't use n +-> f(n) but rather a
function derived from that one.

Is there a way to delete an element from a stream? Eg., in Axiom one can say

delete(s, 2) 

(s being a Stream) and gets the Stream s.1, s.3, s.4,...

Martin




More information about the Aldor-l mailing list