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

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

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

Post 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)
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply