[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: CPS in Parrot (was: A plea for a new old language)



At 2:23 AM -0700 8/7/03, James McCartney wrote:
>On Wednesday, August 6, 2003, at 03:47 PM, Dan Sugalski wrote:
>
>>That, though, may be because there's no difference between the 
>>continuations Parrot uses for its CPS system and continuations it 
>>takes for call/cc or that it gives you when you just want a 
>>continuation for later use.
>
>OK perhaps someone can clear up some confusion for me.
>Assuming you have a language that has mutable variables, and you can 
>write a subroutine that happened to use a global variable as a loop 
>counter and create a first class continuation from within the loop, 
>wouldn't capturing the continuation include/require copying the 
>global environment then?

No. It'd mean you'd have changed global state out from underneath the 
continuation and made things potentially very odd if you reused the 
continuation. Perfectly legitimate, though potentially ill-advised.

>If the global environment were not copied then the continuation 
>could not be resumed more than once with the same behaviour because 
>the global variable could have been mutated.

Yep.

>What does your system do?

It lets you get yourself in a state you probably don't want to be in. 
Loop counters are state, and we don't save state, just metastate. If 
you want to write code that does Evil Nasty Things with globals, 
loops, and continuations, well, you can, and it's really not for us 
to make it so you can't do that.

Not all code has to be safe in the face of continuations. I expect 
it's one of those halting problem class problems to figure out 
definitively whether code is or isn't safe that way.
-- 
                                         Dan

--------------------------------------"it's like this"-------------------
Dan Sugalski                          even samurai
dan@sidhe.org                         have teddy bears and even
                                       teddy bears get drunk