8 ms·
Do any non-Lisp/Scheme languages have continuations?
by pmoriarty 10y ago
Do any non-Lisp/Scheme languages have continuations?
- grzm 10y agoWikipedia provides a list of continuation implementations in a variety of languages: https://en.wikipedia.org/wiki/Continuation#Programming_language_support https://en.wikipedia.org/wiki/Continuation#Programming_langu... Some of these are first-class continuations; others support continuation passing style.
- nathell 10y agoAs an example, here's a simple proof-of-concept webapp I wrote in Ruby, based on continuations: https://github.com/nathell/ruby-continuation-webapp https://github.com/nathell/ruby-continuation-webapp
- deleted 10y ago[deleted]
- rprospero 10y agoHere's the obligatory "Haskell has a monad for that" comment http://hackage.haskell.org/package/mtl-2.2.1/docs/Control-Monad-Cont.html http://hackage.haskell.org/package/mtl-2.2.1/docs/Control-Mo...
- kmill 10y agoSpeaking of monads, one of the themes in Prof. Sussman's "Adventures in advanced symbolic programming" course was that many metacircular evaluator experiments can be set up by using mostly the same core evaluator but swapping out the underlying monad. I'm pretty sure I implemented the "ambivalent operator" that way, using the list monad (in Scheme), but when we lifted amb to the host Scheme, it needed call/cc to be able to use the built-in control flow. One thing I like about Haskell is that it's designed so that adding new control flow is not a big deal -- just design a monad. In Scheme it seems to be more work to get it all right.
- penpapersw 10y agoThat kind of feels like cheating though. I mean, the complicated part of a continuation is that it restores the same context and state that the app had right before the plunge. But Haskell inherently doesn't have "floating" state, it's all self-contained within each parameter. So in Haskell it's more or less a fancy goto-statement.
- mbrock 10y agoThe linked module defines a "monad transformer" that can wrap other monads with a continuation-capturing layer. This means, among other things (Haskell's solution is awesomely general) that you can indeed use it with state, if you compose it with the state monad, or even the IO monad. (The bottom of the documentation page has a contrived example of this.)
- white-flame 10y agoThere's lots of continuation styles & libraries, but most are delimited continuations. In my opinion, delimited ones are far cleaner to implement and to work with than the more universal continuations of Scheme. call/cc, as a product of Scheme's efforts on simplicity[1], has to encompass a larger amount of low-level state than most real-world uses of it use (and it's used far less frequently in "real applications" than academically). Having a better suite of flow control forms and keeping continuations delimited has far less constraints on the design of the runtime and leads to more focused and explicit operation without a bunch of implicit unused implications hanging around. [1 = simplicity as in fewer built-in operations]
- michaelsbradley 10y agoAny recommendations for write-ups on how delimited continuations are implemented?
- convolvatron 10y agomy reading is that by 'delimited continuations', white-flame is just referring to explicit closures and function calls. which lets you build up event-driven machines in any language that supports closures. the distinction is that in scheme, where (at least in the standard implementation) each function call takes an implicit continuation and the code is everted using a bulk cps-transform before being interpreted or further compiled. in this later case, its possible to use call/cc to create a continuation at any point in a 'normal' program, without having to construct the control flow explicitly. its this 'continuations everywhere' approach that can burden the runtime with a lot of consequences, possibly even precluding the use of a stack at all depending on the implementation. in the former case you can basically do by-hand cps or event-handling in anything. asm, C, c++, python (3), go, js..
- Johnny_Brahms 10y agoCheck out Andy wingo's blog. He implemented delimited continuations for guile, and provides lots of sources for his implementation. And ofcourse everything by Oleg Kiselyov
- 10y ago
- tonyg 10y agoThe Rhino javascript implementation has continuations. Chris Double once stuck it in Jetty, and I threw together a horrifying proof-of-concept Seaside-like continuation-based web programming library based on that: http://homepages.kcbbs.gen.nz/tonyg/lshift_archive/a-rhino-at-the-seaside-20060718.html http://homepages.kcbbs.gen.nz/tonyg/lshift_archive/a-rhino-a... As a proof-of-concept, it was fun, but that's as far as it went :-)
- doublec 10y agoRhino was a fun JS system. One of the continuation examples I did for a talk was migrating threads in Rhino: https://bluishcoder.co.nz/2006/06/11/migrating-javascript-threads.html https://bluishcoder.co.nz/2006/06/11/migrating-javascript-th.... Start a thread on one machine, serialize the continuation and send it across the network and resume it on that machine.
- mamcx 10y agoI wonder how it could affect the performance of a interpreter if is build around (internal) continuations, so all the other cool things as exceptions are made on top of it. I try a small demo, and the complexity of the interpreter get high fast. Also, if not continuation, what else can be used?
- penpapersw 10y agoRuby has `#callcc` which produces first-class continuations AFAIK https://ruby-doc.org/core-2.2.0/Continuation.html https://ruby-doc.org/core-2.2.0/Continuation.html
- paulddraper 10y agoYep. Relatedly, Ruby also has fibers.
- bbcbasic 10y agoC# has async/await and TPL, e.g. .ContinueWith(...) Javscript has promises and async/await
- bbcbasic 10y agoIf anyone can feedback on why my comment is wrong I'd appreciate it. I know we're not meant to comment on downvoting but I want to uncover the error in my understanding of this subject because at least 3 people downvoted but there is no reply yet??
- AstralStorm 10y agoAsync/await does not allow you to suspend a computation and then resume it, and it is not easy to chain.
- bbcbasic 10y agoThanks. I took continuation to include cases where you respond to asynchronous call backs while the program is still executing, in which case suspension isn't needed.
- somethingsimple 10y agoIf you implement your own awaiter with INotifyCompletion [1], you get the continuation as an Action that you can invoke as you will. TBH I haven't done it, but I believe you could use that to implement something akin to call/cc. [1] https://msdn.microsoft.com/en-us/library/system.runtime.compilerservices.inotifycompletion(v=vs.110).aspx https://msdn.microsoft.com/en-us/library/system.runtime.comp...
- protomyth 10y agoSome Smalltalks have them and they are used by Seaside but made optional in Seaside 3.0 because of the platforms that don't have them.