Subject: Re: The fundamental concept of continuations
From: rpw3@rpw3.org (Rob Warnock)
Date: Thu, 18 Oct 2007 03:20:31 -0500
Newsgroups: comp.lang.lisp
Message-ID: <soGdnV8lD6bSioranZ2dnUVZ_hqdnZ2d@speakeasy.net>
Ken Tilton  <kentilton@gmail.com> wrote:
+---------------
| George Neuner wrote:
| > Technically, a continuation is just "whatever happens next". 
| 
| See, this is why need not just dumb trench-digging application 
| programmers like me, we also need supertheoretical functional geniuses 
| to come up the Deep Insights. Until now I thought I was about to make a 
| coffee run, but now I see that even though it will be a new coffee run 
| it is still what happens next and if I get pulled over and the cop wants 
| to know what's the hurry I'll just tell him he is interrupting a Scheme 
| continuation.
+---------------

Ahhh, Kenny, Kenny, you're missing the whole point of "real"
(Schemish) continuations. Here's how your story *should* go,
which may help explain (or not):

0. You're slaving away on Cello version 72531.22.91 when you
   realize you've *got* to have some coffee, but you know you're
   going to be working all night and you only have enough cash
   left after buying that 42nd mongo flatpanel [needed to show
   off the full feature set of Cello version 72531.22.90] to
   buy one cup. Thankfully, you've been reading this thread,
   so you...

1. Put a sticky note on your monitor to remind you what it is
   you want to do next after your coffee break [note (and this
   is very important): you SETF the note, not LET-bind it!!] and
   then you make your coffee run (but *DON'T* drink it yet!!)
   and bring it back to the CelloCAVE, and while it's nice and
   hot, just before you take the first sip, you do a CALL/CC
   and stick the resulting continuation you got into a special
   box on a shelf near the door. Then you...

2. Enjoy your coffee, get your caffeine rush, and head back to
   your coding CAVE and start doing whatever it says on the little
   yellow sticky you put on your monitor in step #1.

Now here's where the real fun starts...

3. Several hours [minutes?!?] later, having used up your caffeine
   rush [but Cello 72531.22.91 still being unfinished], it's time
   for another coffee run, but as noted in #0 you now have no money
   left. No problemo! Make a note to yourself on a little yellow
   sticky saying what you want to do after your coffee and stick
   it on your monitor [SETF, not LET-bind!], then go over next to
   the door and FUNCALL the continuation in the box on the shelf
   by the door, and you...

4. Wake up, just back from the coffee run you made in #1, with a
   hot steaming cut of fresh coffee in your hand, which you enjoy,
   get your rush, and head back to your coding CAVE and start doing
   whatever it says on the little yellow sticky you put on your
   monitor in step #1.

3a. Several hours [minutes?!?] later, having used up your caffeine
   rush [but Cello 72531.22.91 still being unfinished], it's time
   for another coffee run, but as noted in #0 you now have no money
   left. No problemo! Make a note to yourself on a little yellow
   sticky saying what you want to do after your coffee and stick
   it on your monitor [SETF, not LET-bind!], then go over next to
   the door and FUNCALL the continuation in the box on the shelf
   by the door, and you...

4a. Wake up, just back from the coffee run you made in #1, with a
   hot steaming cut of fresh coffee in your hand, which you enjoy,
   get your rush, and head back to your coding CAVE and start doing
   whatever it says on the little yellow sticky you put on your
   monitor in step #1.

And you continue in this way, never having to pay for another cup of
coffee, until Cello 72531.22.91 *is* finally finished, then you...

5. Crash all weekend, and get up on Sunday night just long enough
   to post the announcement of Cello 72531.22.91 [no documentation,
   of course, but it all *WORKS*!!] to "comp.lang.lisp", and then
   crash back in your bed again. [Only to wake up Monday morning
   to discover that the ungrateful yobbos of "c.l.lisp" are all
   bitching about the (lack of) documentation instead of singing
   hosannas about all the new features... But that's another story.]

In a nutshell: The thing that's different about full/real/Schemish
continuations is that you can call them more than once. But note
that only the *control* path is repeated; any globals that you
SETF'd [such as the yello sticky] *aren't* reset when you call the
continuation a 2nd, 3rd, 4th, etc., time, so you can use them to
tell the difference between successive FUNCALLs of the continuation.


-Rob

p.s. Smart Schemers will realize I've cheated in the above story.
Well, unless somebody knows how to instantiate a cup of coffee
entirely in the control path and not in a stateful "coffee-mug object"
whose mutations (and eventual emptiness) *will* be noticed across
reinvocations of the continuation.

-----
Rob Warnock			<rpw3@rpw3.org>
627 26th Avenue			<URL:http://rpw3.org/>
San Mateo, CA 94403		(650)572-2607