Scala Call-by-name Parameters

There are two ways to give parameters to a function in most programming languages: 'by-value' and 'call-by-name'.

The 'by-value' way is what we have seen in previous SKBs when we used functions and methods.

In this SKB, focus your attention on the way the parameters of the function are being declared and the syntax, notice anything?

Did you notice the => Int in the parameter list?

You can understand it as if it was () => Int, meaning a function that will return Int when called.

The content of the parameter will not be evaluated until needed. Be aware that it will be re-evaluated for each time it is called. But we will look into it into a more advanced SKB later on.

Reveal more information and clues
Load Exercise