5 ms·
Call/cc for C programmers (2012)
- homu505 8y agoSite is down.
- agumonkey 8y agoarchived https://archive.fo/wGHY https://archive.fo/wGHY 6 years ago
- SamReidHughes 8y agoLink says (2017), ironically.
- bhrgunatha 8y agoIt does seem to fail quite a lot - so much that I bookmarked the wayback machine which has a good deal of it archived. [1] https://web.archive.org/web/20180128095717/http://community.schemewiki.org:80/ https://web.archive.org/web/20180128095717/http://community....
- nickpsecurity 8y agoPreviously discussed here: https://news.ycombinator.com/item?id=10214012 https://news.ycombinator.com/item?id=10214012
- sbjs 8y agoThis is fascinating, but it seems like it only applies to "one shot" programs, like compilers. How applicable is this in the web application space, where state is usually stored externally to the process itself? If used in the way pg's Arc was intended for making web sites easier to reason about developing, then stopping your server results in losing context for follow-up requests. Even modern desktop and mobile apps have a concept of serializing the user's current context in case the computer accidentally shuts down. Context state can't be used safely with call/cc in these situations.
- sillysaurus3 8y agoNot quite true. You can serialize a closure. Emacs lisp does so in a pretty interesting way: a closure is just `(closure ((a . 1) (b . 2)) (lambda (x) (+ x a b)))`. The point is, if you can serialize closures, I think you can serialize continuations.
- sbjs 8y agoAnd how does this work if it involves an open file handle, or some other non serializable state?
- sillysaurus3 8y agohttps://www.usenix.org/system/files/conference/atc12/atc12-final206.pdf https://www.usenix.org/system/files/conference/atc12/atc12-f...
- sillysaurus3 8y agoAlso https://github.com/tvcutsem/schemeken https://github.com/tvcutsem/schemeken is quite interesting, as is https://github.com/supergillis/v8-ken https://github.com/supergillis/v8-ken
- fulafel 8y agoThere are continuation based server-side web frameworks that will serialize & restore the continuation from storage between web requests. Eg Seaside. Rhino can also serialize continuations, there might be a web framework for it too. For frontend, there are some nontrivial transformations needed to compile continuation based code for a JS target. You can't use the native stack, etc. (Same for WebAssembly I gather, judging from the recent Go/WebAssembly implementation discussion)
- zitterbewegung 8y agoThis brings back memories. In high school I helped out with the launch of this wiki.
- mehrdadn 8y agoThe explanation for call/cc has always been extremely roundabout and confusing to me, especially since setjmp/longjmp aren't themselves typically used in C code. Here's a hopefully simple explanation: (call/cc f) means "call f and pass it a customized 'return' procedure, which, when invoked with your desired return value, would make this call/cc invocation return that value right here and continue executing the program".
- sillysaurus3 8y agoSimple, 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.
- dingo_bat 8y ago> Once you've got a continuation object, calling it as say (cont 123) is like a C code longjmp(jbuf, 123) > In Scheme of course any object can be "returned" in this way (and even values? for more than one object), not just a single int. I think the author's last experience with C might be a bit dated.
- deleted 8y ago[deleted]
- fori1to10 8y agoCan't access the link.