all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: George Neuner <gneuner2/@/comcast.net>
To: help-gnu-emacs@gnu.org
Subject: Re: The fundamental concept of continuations
Date: Tue, 09 Oct 2007 14:18:21 -0400	[thread overview]
Message-ID: <m5ang3h11oorvsrkit4q1moi6mirofbdbr__29281.8436435939$1192017355$gmane$org@4ax.com> (raw)
In-Reply-To: 1191906949.179197.217470@57g2000hsv.googlegroups.com

On Tue, 09 Oct 2007 05:15:49 -0000, gnuist006@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 from
http://rapidshare.com/files/24382311/155860698X.Morgan_20Kaufmann.Engineering_20a_20Compiler.pdf


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

  parent reply	other threads:[~2007-10-09 18:18 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1191906949.179197.217470@57g2000hsv.googlegroups.com>
2007-10-09  5:59 ` The fundamental concept of continuations Barb Knox
2007-10-09  6:07 ` Bakul Shah
2007-10-09  6:09 ` .
     [not found] ` <see-36543E.18592809102007@lust.ihug.co.nz>
2007-10-09  6:24   ` gnuist006
     [not found]   ` <1191911045.604596.50110@19g2000hsx.googlegroups.com>
2007-10-09 13:21     ` Joel J. Adamson
2007-10-14 22:56   ` Lawrence D'Oliveiro
2007-10-15  4:17     ` George Neuner
     [not found] ` <470b1aa6$0$79886$742ec2ed@news.sonic.net>
2007-10-09  6:33   ` gnuist006
     [not found]   ` <1191911604.169846.244430@r29g2000hsg.googlegroups.com>
2007-10-09  7:15     ` Bakul Shah
2007-10-09  7:11 ` Peter Danenberg
2007-10-09 12:05 ` Matthias Benkard
     [not found] ` <470b1b30$0$11022$4c368faf@roadrunner.com>
2007-10-09  6:34   ` gnuist006
     [not found]   ` <1191911662.983658.79540@g4g2000hsf.googlegroups.com>
2007-10-09 10:00     ` Tim Bradshaw
     [not found]     ` <1191924032.449463.13290@22g2000hsm.googlegroups.com>
2007-10-09 10:13       ` Diez B. Roggisch
2007-10-09 12:50   ` Matthias Blume
2007-10-09 13:50   ` josephoswald+gg@gmail.com
2007-10-09 19:20   ` gnuist006
     [not found]   ` <m2641g1mgn.fsf@my.address.elsewhere>
2007-10-09 19:37     ` gnuist006
2007-10-09 20:41       ` Chung-chieh Shan
2007-10-10  0:47       ` Matthias Blume
     [not found]       ` <ok5tt4-2ij.ln1@mantle.rutgers.edu>
2007-10-10  4:52         ` Marlene Miller
     [not found]   ` <1191957606.187050.272820@v3g2000hsg.googlegroups.com>
2007-10-09 20:32     ` .
2007-10-09 18:18 ` George Neuner [this message]
     [not found] ` <m5ang3h11oorvsrkit4q1moi6mirofbdbr@4ax.com>
2007-10-09 19:24   ` gnuist006
2007-10-09 19:27 ` Jeff M.
2007-10-10  4:39 ` Marlene Miller
     [not found] ` <8IYOi.658994$p47.379449@bgtnsc04-news.ops.worldnet.att.net>
2007-10-10  4:46   ` Marlene Miller
2007-10-10  7:11 ` Dmitri Minaev
2007-10-10 10:49 ` David Kastrup
     [not found] ` <85zlyrutux.fsf@lola.goethe.zz>
2007-10-11  7:18   ` George Neuner
     [not found]   ` <rqhrg3d2thcqaip790k1eb6t8cdk2g8d8v@4ax.com>
2007-10-12 19:17     ` David Kastrup
     [not found]     ` <85lka8p2h4.fsf@lola.goethe.zz>
2007-10-13  3:11       ` Rob Warnock
2007-10-13  3:13       ` Paul Rubin
     [not found] ` <1191931524.047907.98040@v3g2000hsg.googlegroups.com>
2007-10-13 23:14   ` Alex Martelli
2007-10-09  5:15 gnuist006

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='m5ang3h11oorvsrkit4q1moi6mirofbdbr__29281.8436435939$1192017355$gmane$org@4ax.com' \
    --to=gneuner2/@/comcast.net \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.