This is the mail archive of the
guile@sources.redhat.com
mailing list for the Guile project.
Re: How often are continuations created?
Miroslav Silovic <silovic@zesoi.fer.hr> writes:
> > (do ((i 0 (1+ i)))
> > ((= i N))
> > (vector-set! v i (magic-computation i))) =>
>
> > Since magic-computation is a procedure, %call creates a new frame for
> > it. `i' is still a local variable because magic-computation cannot
> > refer to it. Is there any problem with this?
>
> Well, suppose magic computation, when first invoked, calls call/cc and
> passes it out through some global, then just returns and does a NOP
> until the loop exits
>
> (sample:
>
> (define magic-computation
> (let ((capture #t)
> (if (capture)
> (begin
> (set! capture #f)
> (set! some-cont (call/cc (lambda (cont) cont))))))))
>
> )
>
> Then, when you invoke some-cont, it will return from magic-computation
> and redo the loop - except that the value of i will be 0, when it
> should be N.
Oh, should it? But Guile does restart it from 0:
guile> (define some-cont #f)
guile> (define magic-computation
(let ((capture #t))
(lambda (x)
(if capture
(begin
(set! capture #f)
(set! some-cont (call-with-current-continuation id)))))))
guile> (do ((v (make-vector 5 #f))
(i 0 (1+ i)))
((= i 5))
(vector-set! v i (magic-computation i))
(display i))
01234guile> (some-cont #f)
01234guile>
Which one is the correct behavior?