Skip to content

Instantly share code, notes, and snippets.

@pavel-filatov
Created May 12, 2018 11:37
Show Gist options
  • Save pavel-filatov/f984515ca29e652b8043dc14a023269f to your computer and use it in GitHub Desktop.
Save pavel-filatov/f984515ca29e652b8043dc14a023269f to your computer and use it in GitHub Desktop.
Scala Evaluation Rules
def example = 2 // 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
@pavel-filatov
Copy link
Author

  • 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment