3 ms·
Simple, but missing many parts. For example, what happens to variables on the stack? The heap? What does it mean to continue execution from “here” — from this p
by sillysaurus3 8y ago
Simple, but missing many parts. For example, what happens to variables on the stack? The heap? What does it mean to continue execution from “here” — from this point in time? Does that mean file handles will be closed or re-opened to match the current state of the program?
These questions usually have straightforward answers, but some are counterintuitive.
- mehrdadn 8y agoWhat do you mean what happens to them? Wouldn't they just be kept alive with the same semantics as how a variable used in a nested function is kept alive? Or is there more that I'm not aware of? If that's all there is to it, the semantics should be second nature if you've done Java, Python, or any other GC'd language, right?
- sillysaurus3 8y agoThat’s one option. But the unfortunate conclusion of that choice is that continuations leak a lot of memory. One shot continuations are better, since it frees up the variable references.
- mehrdadn 8y agoI don't see how this is different from lambdas in general, in JS/Python/etc... wouldn't it only be held as long as the variables are alive? If you use the callback only once then they should be eligible to be freed after being used once.
- sillysaurus3 8y agohttp://okmij.org/ftp/continuations/against-callcc.html http://okmij.org/ftp/continuations/against-callcc.html is pretty informative. It was kind of eye opening to see just how many corner cases there are when dealing with continuations. (See the section “memory leaks”.)
- mehrdadn 8y agoThanks for the link! Unfortunately I don't understand what it's saying the issue is... would you have a simple example to illustrate? It's been years since I did Scheme, I've never actually needed to use call/cc in a program, and I'm not advanced enough in Scheme to have seen shift/reset (as with call/c, their documentation is not quite clear). :\
- sillysaurus3 8y agoI could, but not at 3 AM. :) I'll try to remember tomorrow.