[plt-scheme] Fun with Unicode and delimited continuations
On Jun 3, 2010, at 7:22 PM, Matthias Felleisen wrote:
>
> On Jun 3, 2010, at 7:47 PM, John Clements wrote:
>
>>
>> On Jun 3, 2010, at 4:33 PM, Matthias Felleisen wrote:
>>
>>>
>>> Can you return them from the function that grabs them (in Python)?
>>> Can you resume the function once it has transfered control somewhere else?
>>> Can you store the continuations in some vector?
>>>
>>> (I don't know the answers, but these are some of the things one can do with 1st-class values.)
>>
>> Yes:
>>
>> def grabK () : yield 1 ; print "running..." ; yield 2
>>
>> def grabAFewKonts () :
>> return [grabK () , grabK ()]
>>
>> a = grabAFewKonts();
>>
>> f = a[0];
>> g = a[1];
>>
>> print(f.next());
>> print(f.next());
>> print(g.next());
>
>
> Interesting perception. What you are storing are not the continuations but the suspended generators. (Think of grabK() as the creation of a generator.) You could do that in Simula 67, and what you need for that is a pair of control stacks, not a continuation tree.
If I understand you correctly, the procedure-boundary limitation erases the difference between these, right?
Also, FWIW, my understanding is that the presence of 'yield' is detected statically, and the corresponding function expanded into one whose invocation creates a generator, so removing the procedure-boundary limitation would be very difficult.
> So here is the next question then:
>
> Can you invoke them a __second__ time and get an error message about a second use?
> If you can't, they aren't real one-shot continuations. To be precise, you have no
> observation to prove that they are continuations.
You definitely get an error (or special value, I don't know the difference) when the generator is exhausted:
...
print(f.next());
print(f.next());
print(f.next());
=>
1
running...
2
Traceback (most recent call last):
File "/tmp/foo.py", line 13, in <module>
print(f.next());
StopIteration
... but without that behavior, it wouldn't be a generator, so I'm not sure I'm understanding what you're suggesting.
> In the days of denotational semantics, you might have said that you can denote them but not express them (or backwards, Mitch would know).
Ah, those days of yore, when terms had real meanings :). Anyone know of work by philosophers or literary theorists on the significance of the move from denotational to operational semantics?
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/f3b2ff28/attachment.p7s>