http://scala-blogs.org/2008/09/scalable-language-and-scalable.html
He's also said he'll make his slides from the presentation available (soon?).
--j
First is the code for what I'd like to do. Second is the result of
throwing it
at scala 2.7.0 (final) and third is the result of throwing it at 2.7.2
RC1.
I'd like to be able to use foo.x = y and y = foo.x when x is a
property with
getter and setter methods taking an implicit for context.
----------
case class Context(val country : String) { }
class Foo {
var _x: String = "DEFAULT"
def x()(implicit context : Context) : String = _x
def x_=(value : String)(implicit context : Context) : Unit =
{ _x = value }
}
object Foo {
val foo = new Foo()
implicit val context : Context = Context("US")
def main(args: Array[String]) : Unit = {
foo.x = "Hello"
println(foo.x);
}
}
----------
If I change the two lines of code in main() to call the setter/getter
methods explicitly
then it works fine.
foo.x_=("Hello")
println(foo.x())
But, I want it to work as written above.
----------
$ scala
Welcome to Scala version 2.7.0-final (Java HotSpot(TM) Client VM, Java
1.5.0_13).
Type in expressions to have them evaluated.
Type :help for more information.
scala> case class Context(val country : String) { }
defined class Context
scala>
scala> class Foo {
| var _x: String = "DEFAULT"
| def x()(implicit context : Context) : String = _x
| def x_=(value : String)(implicit context : Context) :
Unit = { _x = value }
| }
defined class Foo
scala>
scala> object Foo {
| val foo = new Foo()
| implicit val context : Context = Context("US")
|
| def main(args: Array[String]) : Unit = {
| foo.x = "Hello"
| println(foo.x);
| }
|
| }
<console>:12: error: assignment to immutable value
foo.x = "Hello"
^
----------
$ scala
Welcome to Scala version 2.7.2.RC1 (Java HotSpot(TM) Client VM, Java
1.5.0_13).
Type in expressions to have them evaluated.
Type :help for more information.
scala> case class Context(val country : String) { }
defined class Context
scala>
scala> class Foo {
| var _x: String = "DEFAULT"
| def x()(implicit context : Context) : String = _x
| def x_=(value : String)(implicit context : Context) :
Unit = { _x = value }
| }
defined class Foo
scala>
scala> object Foo {
| val foo = new Foo()
| implicit val context : Context = Context("US")
|
| def main(args: Array[String]) : Unit = {
| foo.x = "Hello"
| println(foo.x);
| }
|
| }
<console>:12: error: reassignment to val
foo.x = "Hello"
class Foo {
var _x: String = "DEFAULT"
def x(implicit context : Context) : String = _x
def x_=(value : String)(implicit context : Context) : Unit = { _x = value }
}
--j