[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: continuation?

From: Chris Cramer
Subject: Re: continuation?
Date: Tue, 29 Jan 2002 02:10:55 -0600
User-agent: Mutt/1.2.5i

On Sat, Jan 26, 2002 at 04:51:06PM +0900, Seong-Kook Shin wrote:
> I cannot understand what the meaning of `continuation', and
> how to do with `call-with-current-continuation'.

Yeah, it's easily the most confusing thing about Scheme. Luckily,
it's rarely useful, let alone necessary.

> Is there anyone can explain the basic idea of `continuation'
> and can show some simple, brief and fullly explained example?
> Or just let me know which document or book will be a good start.

I will try...

This code:

(define (call-with-true,-return-false proc)
    (proc #t)

(call-with-current-continuation call-with-true,-return-false)

yields #t. call-with-true,-return-false is called, and it then
calls proc. proc in this case is a continuation, so it continues,
causing call-with-current-continuation to return the value
the continuation was called with, in this case #t.

Basically anything of the form:

    (lambda (c)
        (c x)

is equivalent to x, not y.

So it's sort of like setjmp in C, or exceptions in Java. But the really
weird thing is that you can call continuations multiple times, from
anywhere; they can be used just like any normal procedure. The simplest
way I can think of to demonstrate this inane property is:

(define beep "Beep!\a\n")
(define beeping-continuation #f)
            (lambda (continuation)
                (set! beeping-continuation continuation))))
    (display beep))

(beeping-continuation "Hi there. ")
(beeping-continuation "Isn't this annoying? ")
        "One, "
        "Two, "
        "Three, "
        "Four, "))

The map is not as bad as you might think =^D. Try it.

> (1) What's the exact meaning of `application' in the above
>    quotation?  I suppose that meaning might be the same which
>    can be found in the Scheme grammer (also found in the book):
>         <application> -> (<expression> <expression>*)
>     Right?

Yes. A continuation is a procedure, and so you apply it.

> (2) What's the exact meaning of *CURRENT* continuation?
>    Does it mean the expression that will be evaluate next?
>    For example:
>         (call/cc
>           (lambda (k)
>             (* 5 (k 4))))
>         =>4
>     I think that the `current continuation' of above code
>     is "(call/cc (lambda ...))" itself. Right?

I don't know. Visualizing the concept of a continuation in such a way
is impossible for me. BTW I'm convinced that continuations are evidence
that CS researchers have been smoking too much crack.

> (3) What's wrong in this code?
>         (call/cc
>           (lambda (k)
>             (* 5 k)))
>         => ABORT: (wrong-type-arg)

k is a procedure.

C. Ray C. aka Christopher Cramer

reply via email to

[Prev in Thread] Current Thread [Next in Thread]