(note, lvalue is actually a term from the C grammar, I don't know what it's called in Scala!)
Trying to learn Scala... this evening I'm working on an internal DSL for a dynamically scoped language that might resemble PHP syntax.
My REPL is: Welcome to Scala version 2.7.6.final (Java HotSpot(TM) Client VM, Java 1.6.0).
I have some made-up example code:
class $(any: Any) { def update(sym: Symbol, any: Any) { println("line 2 executed");} def ->(sym: Symbol) : $ = { println("line 1 executed"); return this } def update(any: Any) { println("line 3 executed");} }
The following works as expected:
scala> var a = new $(0) a: $ = $@19238ad scala> a('x) = "blah" line 2 executed
On the other hand, why does the following not invoke the 1-parameter update method?
scala> a = 1 :6: error: type mismatch; found : Int(1) required: $ a = 1 ^
While doing some trial and error, I found this syntactical curiousity:
scala> class A { def this_= { print("hello") } } defined class A scala> var a = new A a: A = A@9aca82 scala> a = 2 :6: error: type mismatch; found : Int(2) required: A a = 2 ^ scala> a.this_ :7: error: value this_ is not a member of A a.this_ ^
What is the meaning over overriding "this_" above? Where does it go?
Ultimately, I would like this to work:
a->'x = "blah"
Thanks