From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "." Newsgroups: gmane.emacs.help Subject: Re: The fundamental concept of continuations Date: 09 Oct 2007 06:09:52 GMT Organization: Road Runner High Speed Online http://www.rr.com Message-ID: <470b1b30$0$11022$4c368faf__22079.5616660782$1191912646$gmane$org@roadrunner.com> References: <1191906949.179197.217470@57g2000hsv.googlegroups.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Trace: sea.gmane.org 1191912641 25343 80.91.229.12 (9 Oct 2007 06:50:41 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Tue, 9 Oct 2007 06:50:41 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Oct 09 08:50:31 2007 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1If8vH-0004oZ-6D for geh-help-gnu-emacs@m.gmane.org; Tue, 09 Oct 2007 08:50:31 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1If8vB-00018r-MT for geh-help-gnu-emacs@m.gmane.org; Tue, 09 Oct 2007 02:50:25 -0400 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!postnews.google.com!news1.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!nx01.iad01.newshosting.com!newshosting.com!post02.iad01!roadrunner.com!not-for-mail Original-Newsgroups: comp.lang.scheme, comp.lang.lisp, comp.lang.functional, gnu.emacs.help, comp.lang.python User-Agent: pan 0.120 (Plate of Shrimp) Original-Lines: 50 Original-NNTP-Posting-Host: 69.132.115.121 Original-X-Complaints-To: abuse@rr.com Original-Xref: shelby.stanford.edu comp.lang.scheme:74376 comp.lang.lisp:230755 comp.lang.functional:62584 gnu.emacs.help:152736 comp.lang.python:515495 X-Mailman-Approved-At: Tue, 09 Oct 2007 02:47:28 -0400 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:48243 Archived-At: 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.