From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: gnuist006@gmail.com Newsgroups: gmane.emacs.help Subject: Re: The fundamental concept of continuations Date: Tue, 09 Oct 2007 19:24:23 -0000 Organization: http://groups.google.com Message-ID: <1191957863.093505.293800__46042.6938524053$1191958901$gmane$org@v3g2000hsg.googlegroups.com> References: <1191906949.179197.217470@57g2000hsv.googlegroups.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" X-Trace: sea.gmane.org 1191958896 20707 80.91.229.12 (9 Oct 2007 19:41:36 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Tue, 9 Oct 2007 19:41:36 +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 21:41:34 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 1IfKx7-0000Lc-Ld for geh-help-gnu-emacs@m.gmane.org; Tue, 09 Oct 2007 21:41:13 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IfKx2-0006t7-0o for geh-help-gnu-emacs@m.gmane.org; Tue, 09 Oct 2007 15:41:08 -0400 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!postnews.google.com!v3g2000hsg.googlegroups.com!not-for-mail Original-Newsgroups: comp.lang.scheme, comp.lang.lisp, comp.lang.functional, gnu.emacs.help, comp.lang.python Original-Lines: 100 Original-NNTP-Posting-Host: 75.30.151.83 Original-X-Trace: posting.google.com 1191957866 31634 127.0.0.1 (9 Oct 2007 19:24:26 GMT) Original-X-Complaints-To: groups-abuse@google.com Original-NNTP-Posting-Date: Tue, 9 Oct 2007 19:24:26 +0000 (UTC) In-Reply-To: User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.8.1.7) Gecko/20070914 Firefox/2.0.0.7,gzip(gfe),gzip(gfe) Complaints-To: groups-abuse@google.com Injection-Info: v3g2000hsg.googlegroups.com; posting-host=75.30.151.83; posting-account=ps2QrAMAAAA6_jCuRt2JEIpn5Otqf_w0 Original-Xref: shelby.stanford.edu comp.lang.scheme:74411 comp.lang.lisp:230829 comp.lang.functional:62606 gnu.emacs.help:152770 comp.lang.python:515597 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:48271 Archived-At: Special thanks to many of you for your very decent replies. On Oct 9, 11:18 am, George Neuner wrote: > On Tue, 09 Oct 2007 05:15:49 -0000, gnuist...@gmail.com 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 > > Lambda calculus. Continuation is just a formal term for "what the > code does next". It manifests, literally, as the next instruction(s) > to be executed. > > >(2) its syntax and semantics in emacs lisp, common lisp, scheme > > Lisp does not have explicit continuations so there is no syntax for > them. Continuations in Lisp mainly take the form of function calls, > function returns, exceptions, conditions, etc. Sometimes code is > written in "continuation passing style" (CPS) in which each function > has one or more additional function parameters (the continuations) - > the function terminates by passing its result as an argument to one of > those continuation functions. > > Scheme has explicit continuations based on closures. Closure > continuations are created using CALL-WITH-CURRENT-CONTINUATION > (usually abbreviated as CALL/CC). Some Schemes also recognize a > LET/CC form used mainly for escape continuations (exceptions). > Scheme's closure continuations can be stored in data structures and > used for complex control forms such as multitasking. Like Lisp, > Scheme code also is sometimes written using CPS. > > >(3) Is it present in python and java ? > > It is present in all languages. It generally takes the form of > procedure or function calls, returns, exceptions, etc. > > >(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. > > As I stated above, every function call or return _is_ a continuation > ... their implementation is obvious. > > For the closure form used in Scheme, the implementation is to create a > closure, a data structure containing the function address and some > method of accessing the function's free variables, and to call the > function. How you do this depends greatly on the instruction set. > > >(5) how does it compare to and superior to a function or subroutine > >call. how does it differ. > > Calling closure continuations is a little more complicated and a bit > slower than calling a normal function. Creating the closure in the > first place may be simple or complicated depending on the complexity > of the source code and the processor's instruction set. > > >Thanks a lot. > > >(6) any good readable references that explain it lucidly ? > > Get yourself a good textbook on compilers. Most of the techniques are > applicable to all languages - even for seemingly very different > languages, the differences in their compilers are simply in how the > basic compilation techniques are combined. > > My favorite intermediate-level books are > > Aho, Sethi & Ullman. "Compilers: Principles, Techniques and Tools". > 2nd Ed. 2006. ISBN 0-321-48681-1. > The first edition from 1986, ISBN 0-201-10088-6, is also worth having > if you can still find it. The 1st edition is mainly about procedural > languages, the 2nd gives more time to functional languages and modern > runtime issues like GC and virtual machines. > > Cooper & Torczon, "Engineering a Compiler", 2004. > ISBN 1-55860-698-X (hardcover), 1-55860-699-8 (paperback). > Also available as a restricted 90-day ebook fromhttp://rapidshare.com/files/24382311/155860698X.Morgan_20Kaufmann.Eng... > > There are also some decent intro books available online. They don't > go into excruciating detail but they do cover the basics of code > shaping which is what you are interested in. > > Torben Mogensen. "Basics of Compiler Design"http://www.diku.dk/~torbenm/Basics/ > > "Engineering a Compiler". I don't have this author's name, nor can > Google find it at the moment. I have a copy though (~2MB) - if you > are interested, contact me by email and I'll send it to you. > > Also Google for free CS books. Many older books (including some > classics) that have gone out of print have been released > electronically for free download. > > George > -- > for email reply remove "/" from address