Breaking News: Grepper is joining You.com. Read the official announcement!
Check it out

Call-by-Name (CBN)#

Sumit Rawal answered on May 23, 2023 Popularity 1/10 Helpfulness 1/10

Contents


More Related Answers


Call-by-Name (CBN)#

0

Call-by-name uses the actual argument as is in the function. Let’s see how CBN would evaluate squareSum(2, 4+1).

svg viewer

The advantage of CBN is that a function argument is not evaluated if the corresponding parameter is unused in the evaluation of the function body.

Conclusion

Simply put, CBV will evaluate every expression to its final value before calling the function, regardless of if the function body needs it or not. CBN, on the other hand, will only take the expressions required by the body of the function and pass them to the function just as you passed them. It then reduces the expressions to their final value in the function body.

For instance, we could have a function which takes two parameters, but only uses the first one in its function body.

def func(int x, int y) = {

print(x)

}

You then call that function passing it two expressions.

func(1+1, 1+2)

CBV will start evaluating by:

func(2,3)

CBN will start evaluating by:

print(1+1)

In the next lesson, let’s see if we can figure out which evaluation strategy is the faster option.

Popularity 1/10 Helpfulness 1/10 Language whatever
Source: Grepper
Tags: whatever
Link to this answer
Share Copy Link
Contributed on May 23 2023
Sumit Rawal
0 Answers  Avg Quality 2/10


X

Continue with Google

By continuing, I agree that I have read and agree to Greppers's Terms of Service and Privacy Policy.
X
Grepper Account Login Required

Oops, You will need to install Grepper and log-in to perform this action.