Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

My continuations fall into an infinite loop

29 views
Skip to first unread message

Armando Blancas

unread,
Apr 21, 2012, 6:22:39 PM4/21/12
to
Sorry if this is too basic but couldn't find anything in the archive.

I'm going through some examples in the Scheme wiki and the Scheme Programming Language 4th Ed., and came upon:

(define return #f)

(+ 1 (call/cc
(lambda (cont)
(set! return cont)
1)))

(return 22) => 23

All fine, until I put this in a script. In Gambit, Chicken and Scheme48 the script goes into an infinite loop when I try to load it. I'll venture to guess that the continuation goes back to the add the argument to 1 and it doesn't stop there, it advances to its own call and back again with 22; as if the continuation is the rest of the program.

I wonder how I can get this to work in a script. I feel as though I'm missing something terribly obvious since there's no mention of any possible issue in tutorials and books I've seen.

Nils M Holm

unread,
Apr 22, 2012, 1:31:38 AM4/22/12
to
Armando Blancas <abm2...@gmail.com> wrote:
> I'm going through some examples in the Scheme wiki and the Scheme
> Programming Language 4th Ed., and came upon:
>
> (define return #f)
>
> (+ 1 (call/cc
> (lambda (cont)
> (set! return cont)
> 1)))
>
> (return 22) => 23
>
> All fine, until I put this in a script. In Gambit, Chicken and
> Scheme48 the script goes into an infinite loop when I try to load
> it. [...]

My guess would be that the result of this program depends
on REPL semantics, which is a gaping hole in the formal
specification of all Schemes up to and including R5RS.

What is the continuation of (+ 1 (call/cc ...)) in your example?

What is the continuation when you package your program in a BEGIN?

--
Nils M Holm < n m h @ t 3 x . o r g > www.t3x.org

Armando Blancas

unread,
Apr 22, 2012, 1:12:58 PM4/22/12
to
> What is the continuation of (+ 1 (call/cc ...)) in your example?
>
> What is the continuation when you package your program in a BEGIN?

At the REPL I get a function that adds one to the argument in both cases and it all works. In a script, using a begin won't help.

I actually suspected that the looping nature of a REPL may be what sets up a top-level end of a continuation that a script won't usually have for these type of use case. I just saw a mention of the REPL in Daniel Friedman's "Applications of Continuations" in section II-3.
0 new messages