[erlang-questions] call by value

Daniel Dormont dan@REDACTED
Mon May 23 04:29:58 CEST 2011


On Sun, May 22, 2011 at 9:33 PM, Richard O'Keefe <ok@REDACTED> wrote:

>
> On 20/05/2011, at 11:59 PM, Martin Dimitrov wrote:
>
> >
> >> but for "values" that are (references to) linked structures,
> >> no copying is done.
> >>
> > If you are talking about Java, isn't this copy-by-reference?
>
> I've never seen the term "copy-by-reference" before,
> so I can't tell.  It certainly isn't PASS by reference.
>
> void incr(int &x) {
>    x++;
> }
>
> int main(void) {
>    int b = 2;
>    incr(b);
>    cout << b << endl;
> }
>
> in C++ (a) uses pass by reference, and (b) prints 3.
> You cannot do that in Java.
>
> Java has pass by value and ONLY pass by value.
> Some of those values are (perhaps confusingly)
> called "object references" (in practice they are
> almost always just plain pointers, something
> Java is, again misleadingly, said not to have).,
>
>
Correct. Remember Java came from C++, and in the early days most people
expressing interest in Java were C++ programmers. The "no pointers" phrasing
was meant to emphasize the fact that Java's pointers were opaque, not
constructible and you could not perform arithmetic on them.

Relatedly when I first read about Refs in Erlang, I assumed they were
similar to the ones in ML or Haskell, that is, immutable references to
mutable data elements. That took correcting.

dan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20110522/981f58bb/attachment.htm>


More information about the erlang-questions mailing list