[plt-scheme] Fun with Unicode and delimited continuations

From: John Clements (clements at brinckerhoff.org)
Date: Fri Jun 4 15:39:30 EDT 2010

On Jun 4, 2010, at 10:54 AM, Matthias Felleisen wrote:

> 
> On Jun 4, 2010, at 1:45 PM, Sam Tobin-Hochstadt wrote:
> 
>> They're one-shot in that they can only be invoked once - after that,
>> they change to do something else.  Consider this implementation of
>> `call/cc':
>> 
>> (define (call/cc* f)
>> (let/cc k
>>   (let* ([v #f]
>>           [k* (lambda (e) (if v (error 'too-many) (begin (set! v #t) (k e)))])
>>     (f k*))))
>> 
>> This implements a first-class, full continuation that can only be used
>> once.  You can pass it back out, invoke it from anywhere, but after
>> one use it errors.  That's a one-shot continuation.
> 
> 
> Please re-read Friedman and Haynes. At a min, run (k* (f k*)). 

IIUC, you're asking what happens if you inject a call to the continuation into a context that is the result of invoking the continuation?

In Python:

def grabK () :
    f = yield 1 ;
    print "running..." ;
    fresult = f()
    yield fresult


f = grabK();

def const8 () : return 8;

def invokefwithconst8 () : f.send(const8)

print(f.next());
print(f.send(invokefwithconst8));

... to which python responds:

pcp062805pcs:/tmp clements$ python /tmp/foo.py
1
running...
Traceback (most recent call last):
  File "/tmp/foo.py", line 15, in <module>
    print(f.send(invokefwithconst8));
  File "/tmp/foo.py", line 4, in grabK
    fresult = f()
  File "/tmp/foo.py", line 12, in invokefwithconst8
    def invokefwithconst8 () : f.send(const8)
ValueError: generator already executing

... which last line makes it clear that the python implementors are also thinking of these as coroutines.

> 
>>> (My true point is that they aren't continuation at all. You can use continuations in the denotational sense to explain them but I think you can get away with something much much simpler: procedure-local continuations, and they are NOT first-class.)

I'm still wrestling with what exactly you mean by "first-class" in this context. I think it has something to do with "can't be nicely expressed without lots of yucky mutation."  If there's a paper I should go read, tell me which one it is.

John

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4669 bytes
Desc: not available
URL: <http://lists.racket-lang.org/users/archive/attachments/20100604/89da91e9/attachment.p7s>

Posted on the users mailing list.