Re: cl-cont

17 views
Skip to first unread message

Vyacheslav Akhmechet

unread,
Nov 13, 2007, 2:44:23 PM11/13/07
to Slobodan Blazeski, webl...@googlegroups.com
On 11/13/07, Slobodan Blazeski <slobodan...@gmail.com> wrote:
> Did you decided to go for continuation based model like ucw or just
> plan to use continuations to implement coroutines than proceed with
> coroutine planned model as you planned ?
Well, I ended up using continuations, but because they're delimited
they pretty much act as coroutines.

> Why did you decided to write
> call/cc from scratch instead of using arnesi.
Initially I was going to write a simple CPS transformer to better
understand what's happening, and then switch to Arnesi. By the time I
understood everything I needed, I already had an almost complete
WITH-CALL/CC implementation, so I didn't want to throw it away. Also,
CL-CONT does a compile time transformation while ARNESI/CC uses an
interpreter for a subset of Common Lisp. The approaches are slightly
different. However, you can use ARNESI/CC instead of CL-CONT with
Weblocks with very minor modifications (they use KALL to restore
continuations, while CL-CONT allows you to just use FUNCALL).

> I started to understand
> how Scheme continuations are working but cl-cont seems like a
> different beast . Few examples from
> http://www.ccs.neu.edu/home/dorai/t-y-scheme/t-y-scheme-Z-H-15.html#node_chap_13
> CNT> (with-call/cc (+ 1 (call/cc
> (lambda (k)
> (setf cc k)
> (+ 2 (funcall k 3))))))
> 6
> CNT> (funcall cc 4)
> 5
> > (define cc #f)
> > (+ 1 (call/cc
> (lambda (k)
> (set! cc k)
> (+ 2 (k 3)))))
> 4
> > (cc 4)
> 5
> Is this bug or planned design?
In Scheme when you restart a continuation you forget about your
*entire* computation, and just switch to the saved one. This is why
saying (+ 2 (k 3)) will ignore the '+ 2' bit: you've switched to k and
will never get back to '+ 2'. This isn't the case in CL-CONT. The
expression (k 3) eventually returns, and 2 is added to it. In CL-CONT
continuations are "delimited", meaning only a small part of your code
(transformed with WITH-CALL/CC) can be saved and restored - the rest
operates as usual. Running this example in Arnesi gives a more
"schemish" result, but they fake it by throwing the value out and
ignoring '+ 2' that way. I could do that, but I feel like that
introduces unnecessary magic and hides the main point - that
continuations are delimited.

> Or something more serious :
> > (list (+ 1 (call/cc
> (lambda (k)
> (set! cc k)
> (+ 2 (k 3))))))
> (4)
> > (cc 4)
> (5)
> CNT> (with-call/cc (list (+ 1 (call/cc
> (lambda (k)
> (setf cc k)
> (+ 2 (funcall k 3)))))))
> throws an error, backtrace at the bottom , sbcl + slime
This fails because (funcall k 3) calls a continuation which adds 1 to
3, which in turn calls the continuation that converts the value 4 into
a list. The resulting value is then returned and there is an attempt
to add 2 to it. But because you can't add 2 to a list you get an
error. Again, this is because continuations are delimited and I make
no attempt to hide it from within CALL/CC. I could hide it by cleverly
throwing out values to ignore '+ 2' here, but again, that will give an
incorrect perception that continuations aren't delimited which can
later bite people when they get unreasonable expectations of what the
code can do.

> I'm not quite able to grasp what delimited continuations means in cl-cont.
> Could you provide more examples or some textual explanation .
Here's Bill Clementson's post that might help:
http://bc.tech.coop/blog/050731.html
Honestly, I could never fully understand this until I wrote my own
transformer. I'll try to write an article that explains this stuff for
those who are interested. The good news is that you don't need to
understand this to use control flow functionality in Weblocks, as it's
packaged up into a higher level of abstraction. I'll soon check in the
updated version of the demo that uses this functionality.

> Also what do you plan about ACL 8.1 are you dropping the support for it?
I need to finish up with modal dialogs, updated demo, and perhaps an
article on how all of this works. After that I'll take a look at
outstanding issues and patched that people have sent in.

Reply all
Reply to author
Forward
0 new messages