9 comments

[ 5.2 ms ] story [ 33.8 ms ] thread
Adding continuations in a "dot" release seems a pretty big deal!
It is a major release of Scala, as the announcement states.
"Support for continuations. A compiler plugin will support continuations as an optional feature of Scala, using a type-directed continuation passing transform. Continuations are useful to implement advanced control constructs, for instance for asynchronous I/O, user interface event handling, or dataflow concurrency."

I didn't think continuations were possible on the JVM. Any idea how they're doing this?

"using a type-directed continuation passing transform."

So it converts your program to continuation-passing style, which you can do in any environment if you're willing to mangle the program enough. I would not expect it to be fast.

My understanding is that Scala already wraps lambdas in internal class instances with a `call` method, so I would imagine that CPS will carry a similar performance and memory hit.

It certainly won't be quite as fast as idiomatic Java code, but it should be considerably faster than other non-local exit implementations that rely on exception handling to manipulate the stack.

http://blog.richdougherty.com/2009/02/delimited-continuation...

It sounds like you will only be able to do continuations within Scala code, not over a call-stack that includes Java/Scala transitions.

(...which is entirely feasible. After all, many interpreters for continuation-friendly languages are built on top of C, which has no continuations.)

I think that the key bit is having it be type directed, so that they can have an explicit concrete representation of the stack as a datastructure that the jvm can optimize, but thats just me speculating
Honestly, I'm most excited about the seemingly mundane parts of this update: named and default args, and package objects. The big reason that Scala appeals to me more than Haskell or ML for building non-trivial systems is the pragmatic way it approaches real-world program construction.

I think that adopting the best features of existing OO languages like Python (named/default args, first-class packages) and Ruby (flexible syntax for pseudo-DSLs, pervasive use of lambdas/blocks in stdlib for iteration and control) while running atop the JVM is a great strategy.