<div class="gmail_quote">On Sun, May 22, 2011 at 9:33 PM, Richard O'Keefe <span dir="ltr"><<a href="mailto:ok@cs.otago.ac.nz">ok@cs.otago.ac.nz</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="im"><br>
On 20/05/2011, at 11:59 PM, Martin Dimitrov wrote:<br>
<br>
><br>
>> but for "values" that are (references to) linked structures,<br>
>> no copying is done.<br>
>><br>
> If you are talking about Java, isn't this copy-by-reference?<br>
<br>
</div>I've never seen the term "copy-by-reference" before,<br>
so I can't tell. It certainly isn't PASS by reference.<br>
<br>
void incr(int &x) {<br>
x++;<br>
}<br>
<br>
int main(void) {<br>
int b = 2;<br>
incr(b);<br>
cout << b << endl;<br>
}<br>
<br>
in C++ (a) uses pass by reference, and (b) prints 3.<br>
You cannot do that in Java.<br>
<br>
Java has pass by value and ONLY pass by value.<br>
Some of those values are (perhaps confusingly)<br>
called "object references" (in practice they are<br>
almost always just plain pointers, something<br>
Java is, again misleadingly, said not to have).,<br>
<div><div class="h5"><br>
</div></div></blockquote><div><br>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.<br>
<br>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.<br><br>dan<br><br></div></div><br>