[Top][All Lists]

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

Re: The fundamental concept of continuations

From: .
Subject: Re: The fundamental concept of continuations
Date: 09 Oct 2007 06:09:52 GMT
User-agent: pan 0.120 (Plate of Shrimp)

On Tue, 09 Oct 2007 05:15:49 +0000, gnuist006 wrote:

> Again I am depressed to encounter a fundamentally new concept that I
> was all along unheard of. Its not even in paul graham's book where i
> learnt part of Lisp. Its in Marc Feeley's video.
> Can anyone explain:
> (1) its origin
One of the lambda papers, I think.  I don't remember which.

> (2) its syntax and semantics in emacs lisp, common lisp, scheme
elisp and Common Lisp don't have them (although sbcl and maybe others user
continuations internally).  In scheme CALL-WITH-CURRENT-CONTINUATION takes
a function of one argument, which is bound to the current continuation. 
Calling the continuation on some value behaves like
CALL-WITH-CURRENT-CONTINUATION returning that value.  So 
 (call/cc (lambda (k) (k 42))) => 42
You can think of it as turning the whatever would happen after call/cc
was called into a function.  The most practical use for continuations in
implementing control structures, though there are some other neat tricks
you can play with them.

> (3) Is it present in python and java ?
Certainly not Java, I dunno about Python.  I've never seen someone use
them in Python, but the pythonistas seem to want to add everything but a
decent lambda to their language so I wouldn't be surprised if someone had
added a call/cc.  Ruby has it.

> (4) Its implementation in assembly. for example in the manner that
> pointer fundamentally arises from indirect addressing and nothing new.
> So how do you juggle PC to do it.
You have Lisp in Small Pieces.  Read Lisp in Small Pieces.

> (5) how does it compare to and superior to a function or subroutine
> call. how does it differ.
You use them like a function call.  You can also use them like
setjmp/longjmp in C.  You can implement coroutines with them, or
events, or simulate non-determinism or write things like ((call/cc call/cc)
(call/cc call/cc)) and make your head explode, use it like goto's inbred
second cousin or in general whatever perverse things you might like to do
with the flow of control in your program. 

> Thanks a lot.
> (6) any good readable references that explain it lucidly ?

Lisp in Small Pieces for implementation details,  the Scheme Programming
Language for examples.

reply via email to

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