fork download
  1. class Lazy[A](thunk : () => A) {
  2. lazy val body = thunk()
  3. }
  4.  
  5. object Lazy {
  6. def lazy[A](x : => A) = new Lazy(() => x)
  7. def force[A](x : Lazy[A]) = x.body
  8. }
  9.  
  10. object Main {
  11. def getX() = {
  12. println("hello")
  13. 3
  14. }
  15. def main(args: Array[String]) {
  16. import Lazy._
  17. val x = lazy(getX())
  18. println("start")
  19. println(x)
  20. println(x)
  21. println(x)
  22. }
  23. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.scala:6: error: identifier expected but 'lazy' found.
  def lazy[A](x : => A) = new Lazy(() => x)
      ^
Main.scala:17: error: illegal start of simple expression
    val x = lazy(getX())
            ^
two errors found
stdout
Standard output is empty