Keith Thompson <Keith.S.Thompson+
u@gmail.com> writes:
Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
[...]
The "call by" in Algol 60 is used to characterize /parameters/ of
a function definition. It's important that "call" is used in the
active voice; parameters are not "called".
>
https://dl.acm.org/doi/pdf/10.1145/367236.367262
>
4.7.5.4. A formal parameter which is called by value cannot in
general correspond to [...]
>
Apparently the author of that section did think that parameters (at
least formal parameters) are "called", or did not clearly express what
he actually meant.
>
It's a minor point.
After some further thought and re-reading of the Algol 60 Report, I
no longer think this is a minor point.
I had said, and you agreed, that parameters are not "called".
I've searched the Algol 60 Report for occurences of "call". It uses
that word both to refer to calling procedures *and* to "calling"
parameters.
And my tentative conclusion is that this whole controversy ("call-by"
vs. "pass-by") is simpler than I had thought, and likely than you
had thought. The phrase "call by value" made sense when the Algol 60
Report was written, because it was understood at the time that
parameters are *called*. It no longer makes as much sense, because
that usage of the word "call" has almost entirely died out, and we say
that arguments are *passed*.
Gory details follow.
Some terminology for those who might not be familiar with Algol 60:
Algol 60 has "procedures", which may or may not return a value.
These correspond to C "functions". Other languages might use terms
like "subprogram" or "subroutine".
Procedures may have parameters. Procedure calls may include
arguments, which are associated with the parameters of the called
procedure. C uses the same terminology (but does not have by-name
semantics). Some languages refer to parameters and arguments as
formal parameters and actual parameters, respectively.
What C calls a "function call", Algol 60 calls a "procedure statement".
The following is partial list of uses of "call" in the Report.
The word "pass" does not appear anywhere in the Report.
4.7.3. Semantics
A procedure statement serves to invoke (call for) the execution of a
procedure body (cf. section 5.4. Procedure Declarations).
4.7.3.1. Value assignment (call by value)
4.7.3.2. Name replacement (call by name)
4.7.5.1. Strings cannot occur as actual parameters in procedure
statements calling procedure declarations having ALGOL 60
statements as their bodies (cf. section 4.7.8).
4.7.5.2. A formal parameter which occurs as a left part variable
in an assignment statement within the procedure body and which
is not called by value can only correspond to an actual parameter
which is a variable (special case of expression].
4.7.5.3. A formal parameter which is used within the procedure
body as an array identifier can only corre- spond to an actual
parameter which is an array identifier of an array of the same
dimensions. In addition if the formal parameter is called by
value the local array created during the call will have the
same subscript bounds as the actual array.
4.7.5.4. A formal parameter which is called by value cannot in
general [...]
5.4.5. Specifications
[...] In this part no formal parameter may occur more than
once and formal parameters called by name (cf. section 4.7.3.2)
may be omitted altogether.
From these examples, it's clear (to me) that the Report uses the word
"call" in its modern sense of calling a function -- but it *also* uses
the word "call" in reference to formal parameters.
Consider this C code:
void func(int param1, int param2) { /* ... */ }
...
func(10, 20);
In C terms, the last line *calls* the function; this includes
*passing* the arguments 10 and 20, which results in assigning those
values to the parameters param1 and param2.
In Algol 60 terms, the last line *calls* the function (procedure); this
includes *calling* the formal parameters param1 and param2. If the
parameters are called by value, the argument values are copied as in C.
If the parameters are called by name, each occurrence of a parameter
name in the body of func() is logically replaced by the argument
expression. (I'm not sure I've described the semantics entirely
correctly.)
Consider this C++ code:
void func(int by_value, int& by_reference) { /* ... */ }
...
int n;
func(42, n);
In the function call, there are two different argument passing
mechanisms, but only one *call*. The call itself is not by
value or by reference. The call includes passing two arguments,
one by value and one by reference. This is one reason I don't
think it makes sense to use "call by" rather than "pass by"
for arguments/parameters. (In Algol 60 terms, parameters were
"called", so that terminology made sense.)
The "call by name" semantics turned out to be more complicated
than expected, and as far as I can tell was never adopted by any
language other than Algol 60.
And in modern usage, the word "call" is used to refer to invoking
a function/procedure/subprogram, and is virtually *never*
applied to associating an argument to a parameter as part of a
function/procedure/subprogram call, other than in the legacy "call
by ..." phrasing. That mechanism is almost always referred to as
*passing* the argument.
In C, function arguments are always passed by value. In C++,
arguments may be passed by value or by reference. In some languages,
some arguments may be passed by copy-in/copy-out. I've never
found the word "pass" to cause any confusion in the latter case.
I might say informally that the argument is passed in on the call,
and then passed out, back to the caller, when the function returns.
My conclusion is that the only reason the term "call by <mechanism>"
is used is because of its use in the very influential Algol
60 Report, which was written at a time when the word "call" was
applied to parameters. Now that that meaning of "call" has almost
completely fallen into disuse, I suggest that "call by <mechanism>"
is of historical interest, but "pass by <mechanism>" is much clearer.
Still, it's important to recognize the "call by" phrasing, which
still appears in the index of K&R2 and the C and C++ standards.
I'd still use the phrase "call by name" rather than "pass by name"
because it's well known by that phrase. For mechanisms that are
still in use in modern languages, I see no point in using the
older terminology.
I don't know whether the idea of "calling" parameters originated in
the Algol 60 report, or whether it was just common usage at the time.
Studying the early documentation for languages like Fortran, Cobol,
and perhaps PL/I might be illuminating, but I have not (yet) done so.
-- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.comvoid Void(void) { Void(); } /* The recursive call of the void */