Well, call by name will reduce the first expression without reducing the argument. So, it would just yield one in a single step, the first argument. And the variation would stop in a value, obviously. And a call by value, we have to reduce the arguments to this expression so we have to reduce loop. And, well, we know that loop reduces to itself, so we would reduce the arguments. Infinitely often, the whole expression would always reduce to itself and we would make no progress. So, that's another example of an infinite loop. In Scala, we normally use call by value. You might ask, well, given the advantages of call by name that it terminates more often, why call by value? Well, it turns out that, for expressions in practice, call by value is often exponentially more efficient than call by name because it avoids this repeated recomputation of argument expressions that call by name entails. The other argument for call by value is that it plays much nicer with, imperative effects and side effects because you tend to know much better when expressions will be evaluated. Since Scala is also an, an imperative side, call by value is the standard choice. Except that, sometimes you really want to force call by name, and Scala lets you do that also. You do that by adding a, an arrow in front of the parameter type. So, this function constOne takes an x parameter int and a y parameter of type arrow int.



Comments