Are the call-by-name concepts and are conveyed on separate distinct concepts?

In my head, at least I always had a good idea about passing value versus functions. I'm going through Scala, although it seems like this notion of calling by name is related, but its own clear concept

For example, in C # there is a ref keyword, and in Scala there is a call called => operator.

I understand that the ref keyword - roughly at least - serves to pass a pointer to a chunk of data, not to that chunk of data. that is, when used with Integer data type, if you change Integer inside a function, Integer will also affect the callee side.

Calling by name in hand describes an evaluation strategy in which any expressions in the argument will be deferred until the expressions are used inside the function.

Is my understanding correct? If so, does it happen that these concepts have associated names, or am I missing part of the picture? Thank!

+3


source to share


1 answer


Are call-by-name and pass-by-reference concepts separate concepts?

Yes. These are separate concepts. Calling by name is when we evaluate; pass-by-reference is what we're going through.

Calling by name means that the function argument is evaluated every time the function uses it, not before the function receives it.

Call by value (aka pass by value) means



  • the function argument is evaluated before the function receives it, and
  • "the resulting value is bound to the corresponding variable in the function."

Call by reference (called pass by reference) means that the function receives "an implicit reference to the variable ... and not a copy of its value".

While call by name is a lax evaluation strategy, call by value and call by reference are two different strict (impatient) evaluation strategies.

See also https://en.wikipedia.org/wiki/Evaluation_strategy

+1


source







All Articles