4

Currently I am taking a course on concepts of programming languages, which is where I came across an issue that had left me confused once before (when I was watching the videos of Martin Odersky's functional programming course on Coursera):

The term "call-by-value" is constantly being used in two different contexts:

Context 1: Evaluation regime (Call-by-value vs. call-by-name)

If a function is being passed an expression as an argument, is that expression being reduced to a value (i.e., evaluated) before the parameter identifiers in the function's body are substituted with it? If so, it's called call-by-value, if not, it's call-by-name. At least that's how I understand it.

Context 2: Parameter passing (Call-by-value vs. call-by-reference)

If a function is being passed an identifier as an argument, is the function's body being evaluated with a new name binding that points to a copy of what the given identifier points at, or can the function actually make changes to what the identifier points at, i.e., changes that are "visible" to the calling context? Again, the first variant would be call-by-value, whereas the second one would be call-by-reference. If I got it right, of course.

However, even though I fail to see a relation between the two use cases of the term "call-by-value", it seems too much of a coincidence for the term to be used in both scenarios by accident.

Does someone know why the same term was chosen to describle two (seemingly different) matters?

typeduke
  • 6,494
  • 6
  • 25
  • 34
  • 2
    Call by reference is call by value with the value being a reference. – Sylwester Aug 30 '15 at 13:30
  • Both seem to be very much the same thing to me. Both cases essentially boil down to: *is the "literal" thing being passed into the function, or only whatever value that literal evaluates to.* – deceze Aug 30 '15 at 13:34
  • 2
    Yeah, it seems the "value" in both contexts mean different things. In the first, the "value" is the result of evaluating an expression. Taking C++ which doesn't use call-by-name, in `void f(int &i); int main() { f(*(new int)); }` the "value" (as in the first category) refers to an object/points to a storage location. Yet, we are using pass-by-reference because in the second context, "value" means what the storage location contains, as opposed to the location itself. – Johannes Schaub - litb Sep 01 '15 at 22:14
  • 1
    In C++ this term "value" is also a bit "overloaded". The Standard defines it as the meaning of the set of bits that an object stores, but at the same time the Standard has the concept of "value category" and "value computation" in which "value" means something more like in context 1 (see http://stackoverflow.com/a/14005563/34509 in which both meanings appear in the same sentence!) – Johannes Schaub - litb Sep 01 '15 at 22:21

1 Answers1

1

Your analysis is correct, and I also find the overloading of the phrase "call-by-value" to be confusing.

Adopting language from the relevant Wikipedia article, call-by-value and call-by-reference can be considered two variants of "strict evaluation", while call-by-name is a type of "non-strict evaluation".

To answer your question, I have a conjecture that the sloppy use of the phrase "call-by-value" to refer to "strict evaluation" in general is born out of the fact that call-by-value is the type of strict evaluation implemented by some of the most popular imperative programming languages. Some old lecture notes from a PL course at UMD conflate the two contexts you describe. They refer to protection of arguments against modification as "another feature" of call-by-value in C, C++, and Java (slide 21), where strict evaluation is implied (erroneously IMHO) to be the definitive feature of call-by-value.

Tag
  • 123
  • 1
  • 10