[erlang-questions] call by value

Richard O'Keefe ok@REDACTED
Fri May 20 11:22:40 CEST 2011


On 20/05/2011, at 4:23 AM, Jesper Louis Andersen wrote:

> On Thu, May 19, 2011 at 17:36, Martin Dimitrov <mrtndimitrov@REDACTED> wrote:
> 
>> "All calls with variables in Erlang are call by value: all arguments to
>> a function call are evaluated before the body of the function is
>> evaluated. The concept of call by reference does not exist, ..."
> 
> I'll reply even though others have replied and add a bit more flesh.
> Suppose we have a function:
> 
> f(X) ->
>  X + 7.
> 
> and we want to call it like this:
> 
> f(3 + 5),
> 
> now there are two ways the reduction can proceed. Either we first
> evaluate the expression and then make the call,
> 
> f(3 + 5) ==> f(8) ==> 8 + 7 ==> 15
> 
> which is the call-by-value evaluation strategy, or we do it by
> substituting in the expression first,
> 
> f(3 + 5) ==> (3 + 5) + 7 ==> 8 + 7 ==> 15

That is *NOT* call by reference.
It is call by *NAME*, which is quite difference.
(The Algol 60 committee intended to specify call by reference,
but used the "copy rule" to define it, which to their dismay
specified call by name instead.)

Pascal 'var' parameters are call by reference, not by name.\




More information about the erlang-questions mailing list