A call-by-name mechanism passes a code block to the callee and each time the callee accesses the parameter, the code block is executed and the value is calculated.
If you want to change selection, open document below and click on "Move attachment"
Scala Functions Call-by-Name e it is passed to the function. But what if we need to write a function that accepts as a parameter an expression that we don't want evaluated until it's called within our function? For this circumstance, Scala offers call-by-name parameters.
<span>A call-by-name mechanism passes a code block to the callee and each time the callee accesses the parameter, the code block is executed and the value is calculated.
object Test {
def main(args: Array[String]) {
delayed(time());
}
def time() = {
println("Getting time in nano seconds")
System.nanoTime
}
de
Summary
status
not read
reprioritisations
last reprioritisation on
suggested re-reading day
started reading on
finished reading on
Details
Discussion
Do you want to join discussion? Click here to log in or create user.