Subject: Re: Trying to understand continuations
From: rpw3@rigden.engr.sgi.com (Rob Warnock)
Date: 31 Dec 2000 04:56:55 GMT
Newsgroups: comp.lang.scheme
Message-ID: <92mean$jn2uj$1@fido.engr.sgi.com>
<jaspered@my-deja.com> wrote:
+---------------
| a weakened form of call/cc could be built in ANSI CL as follows:
|   (defun call-with-downward-continuation (body) ...)
+---------------

Note: MzScheme includes a "call/ec" (call-with-escaping-continuation) and
a "let/ec" macro, in addition to the standard call/cc (and a "let/cc" macro).
Some other Schemes have similar things, too.

+---------------
| What sorts of things can [full] continuations of this sort do that
| can't be done with mechanisms like block/return-from, catch/throw, and
| unwind-protect?
+---------------

Virtually anything an unrestricted "goto" in assembler could do, but
in slightly cleaner style, including implementing:

	- Co-routines (and a thread system on top of that).

	- "Generators", or other forms of lazy data or computation.

	- Nondeterminism & backtracking, that is, if one path
	  of data exploration/evolution "fails", you invoke a
	  saved continuation to try (almost) the same thing again.

If you're a CL guy, go buy/read Paul Graham's *excellent* book
"On Lisp", where he shows how to do some of this kind of stuff in
ANSI Common Lisp by defining, as macros, variations of the major
forms that affect and are affected by continuations -- macros named
"=lambda", "=defun", "=values", "=funcall", "=apply", etc. -- as
well as the "choose" and "fail" macros.  [The code from his books
is available on-line at <URL:http://www.paulgraham.com/lisp.html>]


-Rob

-----
Rob Warnock, 31-2-510		rpw3@sgi.com
SGI Network Engineering		http://reality.sgi.com/rpw3/
1600 Amphitheatre Pkwy.		Phone: 650-933-1673
Mountain View, CA  94043	PP-ASEL-IA