SIP-21 - Spores - Scala Documentation


#1

By: Heather Miller, Martin Odersky, and Philipp Haller

Updated September 15th, 2013


This is a companion discussion topic for the original entry at http://docs.scala-lang.org//sips/pending/spores.html

#2

Will the capture syntax support expressions?

I expect the captured expression will be cached at the beginning of spore block.

For example, given:

val x: String = "Hello, World"
spore { () =>
  capture(x.length)
}

Then it can be translated to

val x: String = "Hello, World"

val tmp0 = x.length;
{ () =>
  tmp0
}

The behavior of caching at beginning is important for lazy vals:

object NotSerializable {
  lazy val x: String = "Hello, World"
  def makeClosure = spore { () =>
    capture(x)
  }
}