I am fairly new to Scala. I am trying to understand how/if scala does dynamic binding when a closure is passed as part of a message to an Actor.
I am using Akka 1.2 with Scala 2.9.
I have the following code segment (modified from http://gleichmann.wordpress.com/2010/11/15/functional-scala-closures/)
var minAge = 18
val isAdult = (age: Int) => age >= minAge
actor ! answer(19, isAdult)
minAge = 20
actor ! answer(19, isAdult)
On the actor side, it simply applies isAdult to the first parameter and prints the result. Since Scala uses dynamic binding (so I was told), I would have expected
true
false
but somehow the result is
false
false
So is it true that scala is binding the variable statically and taking 18 as the value of minAge for both answer messages? Is there a way to keep the dynamic binding behavior while using closures in messages?
Thanks!