Scala Spores, safe mobile closures
Many users expressed concern that spores would be both unusable with for- expression syntax, and would be incompatible (without a lot of boilerplate) with normal closures or higher-order functions which take normal functions as arguments.
To remedy the incompatibility with for-expressions, we propose a new capture
syntax.
A stable path is an expression which only contains selections and identifiers (no applications, for example), and for which each selected entity is stable. In this context, stable means that the entity or object in question is introduced by object definitions or by value definitions of non-volatile types.
Adapted from the Scala Language specification (section 3.1), a path is defined to be one of the following:
C.this
, whereC
references a class. The paththis
is taken as a shorthand forC.this
whereC
is the name of the class directly enclosing the reference.x
wherex
is a package.p.x
wherep
is a path andx
is a stable member ofp
. Stable members are packages or members introduced by object definitions or by value definitions of non-volatile types. (Section 3.6 of the SLS.)C.super.x
orC.super[M].x
whereC
references a class andx
references a stable member of the super class or designated parent classM
ofC
. The prefixsuper
is taken as a shorthand forC.super
whereC
is the name of the class directly enclosing the reference.
A path refers to an object, that is, it ends with an identifier.
- Need to make it more convenient to create a nullary spore
- Should objects be allowed in paths? The reason is that they are initialized lazily, so if we don't allow lazy vals, then allowing objects (which could end up being initialized only when the spore is applied) doesn't make a lot of sense.