Why can't i define recursive variable in code block?
- by senia
Why can't i define a variable recursively in a code block?
scala> {
| val fibs: Stream[Int] = 1 #:: fibs.scanLeft(1){_ + _}
| }
<console>:9: error: forward reference extends over definition of value fibs
val fibs: Stream[Int] = 1 #:: fibs.scanLeft(1){_ + _}
^
scala> val fibs: Stream[Int] = 1 #:: fibs.scanLeft(1){_ + _}
fibs: Stream[Int] = Stream(1, ?)
lazy keyword solves this problem, but i can't understand why it works without a code block but throws a compilation error in a code block.