|
``Call by value'' means the caller passes a value to the callee. In
Dylan's case, that value is an object, which can be side-effected by
the callee. (Assignments to the variable named by the parameter
inside the callee have no effect in the caller.)
``Call by reference'' means the address of a variable is passed to
the callee, so the callee, by assigning to its parameter, can change
what object the variable is bound to.
These are, I think, pretty standard definitions for the terms. Some
people disagree. (I don't care.) This definition of ``call by value''
corresponds exactly to what Dylan, Scheme, Java, Eiffel, etc, do,
regardless of what they call it.
Here's an example. Since Dylan uses call by value, this code
causes no change to *the-counter*:
define variable *the-counter* = 0;
define method increment (counter :: <integer>)
=> ()
counter := counter + 1; // insensible in
Dylan
end method increment;
increment(*the-counter*); // doesn't do
anything
whereas this does increment a slot in *the-counter*:
define class <counter> (<object>)
slot value = 0;
end class <counter>;
define constant *the-counter* =
make(<counter>);
define method increment (counter :: <counter>)
=> ()
counter.value := counter.value + 1;
end method increment;
increment(*the-counter*);
If Dylan had call by reference semantics, the
result of the increment in the first example
would be that *the-counter* contains the value 1
afterwards. That isn't what happens.
|