Page 1 of 1

In scala count steps for call by refrence and call by name of ther following function Trace each function call with cbv

Posted: Thu May 26, 2022 9:31 am
by answerhappygod
In scala count steps for call by refrence and call by
name of ther following function
Trace each function call with cbv and cbn, and count the number
of steps needed to do the calculation with each parameter-passing
mechanism. Which “wins”?
def square(x:Int):Int = x*x
def foo(x:Int, y:Int, z:Int):Int = if(x==y) x*x else z
foo(1+3, 2+2, 5)
foo(1, 1, 6+8*square(3))
foo(1+3, square(2), 4+square(5))
foo(3*2, 12, 6)