Scala Evaluation Rules


Evaluation Rules

  • Call by value: evaluates the function arguments before calling the function
  • Call by name: evaluates the function first, and then evaluates the arguments if need be
def example = 2      // method? evaluated when called 
val example = 2      // evaluated immediately
lazy val example = 2 // evaluated once when needed
def square(x: Double)    // call by value
def square(x: => Double) // call by name
def myFct(bindings: Int*) { ... } // bindings is a sequence of int, containing a varying #of arguments

评论

此博客中的热门博文

Nu förbjuder Kina handel med elfenben

Fader av pingyins

Kineserna vill köpa Volvos kompetens