Leo~

On Tue, 16 Nov 2004 16:37:04 +0100, Leopold Toetsch <[EMAIL PROTECTED]> wrote:
> 
> 
> Matt Fowles <[EMAIL PROTECTED]> wrote:
> > Leo~
> 
> > On Tue, 16 Nov 2004 09:23:24 +0100, Leopold Toetsch <[EMAIL PROTECTED]> 
> > wrote:
> 
> >>     i = 0
> >>   lp:
> >>     foo()
> >>     inc i
> >>     if i < 10 goto lp
> 
> > There is one thing I am not sure about here.  The loop will work
> > correctly for each seperate invocation of the appropriate
> > continuation.
> 
> No. Imagine, foo() is not a simple function anymore. Someone e.g. Jens
> Rieks[1], discovers that the algoritm is simpler implemented with
> continuations. So inside foo() the return continuation of foo() is
> copyied, stored elsewhere, passed along to another function, and that
> one now suddenly returns via this continuation to your loop.  If this
> invocation of the continuation would restore registers suddenly the loop
> will become an infinite one, as C<i> is always restored to zero.
> 
> [1] Have a look at runtime/parrot/library/Streams/Sub.imc
> 
> leo
> 

I disagree with that analysis.  Let us consider the actual effect of
such an implementation.

First iteration

i = 0;
foo(); #at this point a continuation created capturing i=0, promoted
by Jens and stuff happens
#eventually it is invoked, restoring i=0
i++; #i = 1
foo(); #at this point a NEW return continuation is created capturing
i=1; promoted by Jens...
#eventually it is invoked, restoring i=1
i++; #i = 2
...

Thus every single invocation of foo will have an i one greater than
the last.  If foo's algorithm had an error and did not use the new
return continuation to recreate its internal continuation each time,
then you would be correct.  But that would be a bug in the
implementation of foo.

As the following code

#set up for foo
foo()
#set other stuff for foo
foo()

would be an infinite loop alway returning immediately after the first
invocation of foo.

I looked at Sub.imc and think it would work because write always
creates a new Continuation for each invocation of write.

Matt
-- 
"Computer Science is merely the post-Turing Decline of Formal Systems Theory."
-???

Reply via email to