<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE message PUBLIC
  "-//MLarc//DTD MLarc output files//EN"
  "../../mlarc.dtd"[
  <!ATTLIST message
    listname CDATA #REQUIRED
    title CDATA #REQUIRED
  >
]>

  <?xml-stylesheet href="../../mlarc.xsl" type="text/xsl"?>


<message 
  url="2002/07/e05cd085c84fab343d2798f03cabcf5e"
  from="Alessandro Baretta &lt;alex@b...&gt;"
  author="Alessandro Baretta"
  date="2002-07-15T19:46:53"
  subject="Re: [Caml-list] Deep copy"
  prev="2002/07/9a687ad070011724873fe56086b999a8"
  next="2002/07/895cd63e4a2de517e299e871590aa4ee"
  prev-in-thread="2002/07/72c2dc79654035cd9f28bd2d5e20f330"
  next-in-thread="2002/07/15f5a5b0e7c6ba77a94ba8a6b6e1d150"
  prev-thread="2002/07/a6ba0ce22f3d5db7ef94de3a44da9825"
  next-thread="2002/07/2fe55408b32aa0c8bbfe694c2fc4d83a"
  root="../../"
  period="month"
  listname="caml-list"
  title="Archives of the Caml mailing list">

<thread subject="RE: [Caml-list] Deep copy">
<msg 
  url="2002/07/f588263f2499215c76c4696e61086612"
  from="zze-MARCHEGAY Michael stagiaire FTRD/DTL/LAN &lt;michael.marchegay@r...&gt;"
  author="zze-MARCHEGAY Michael stagiaire FTRD/DTL/LAN"
  date="2002-07-15T15:24:59"
  subject="RE: [Caml-list] Deep copy">
<msg 
  url="2002/07/0908d34fdb197e026aad915879cf4cd2"
  from="Eray Ozkural &lt;erayo@c...&gt;"
  author="Eray Ozkural"
  date="2002-07-15T15:30:19"
  subject="Re: [Caml-list] Deep copy">
<msg 
  url="2002/07/72c2dc79654035cd9f28bd2d5e20f330"
  from="Alessandro Baretta &lt;alex@b...&gt;"
  author="Alessandro Baretta"
  date="2002-07-15T18:11:41"
  subject="Re: [Caml-list] Deep copy">
</msg>
</msg>
<msg 
  url="2002/07/e05cd085c84fab343d2798f03cabcf5e"
  from="Alessandro Baretta &lt;alex@b...&gt;"
  author="Alessandro Baretta"
  date="2002-07-15T19:46:53"
  subject="Re: [Caml-list] Deep copy">
<msg 
  url="2002/07/15f5a5b0e7c6ba77a94ba8a6b6e1d150"
  from="John Prevost &lt;j.prevost@c...&gt;"
  author="John Prevost"
  date="2002-07-15T22:28:33"
  subject="Re: [Caml-list] Deep copy">
<msg 
  url="2002/07/101f631797d254be4dac4a73b379b0ee"
  from="Alessandro Baretta &lt;alex@b...&gt;"
  author="Alessandro Baretta"
  date="2002-07-15T22:56:31"
  subject="Re: [Caml-list] Deep copy">
<msg 
  url="2002/07/f49c5a97e201b0f6ea5977beb5930c17"
  from="John Prevost &lt;j.prevost@c...&gt;"
  author="John Prevost"
  date="2002-07-16T08:13:08"
  subject="Re: [Caml-list] Deep copy">
</msg>
</msg>
</msg>
</msg>
</msg>
</thread>

<contents>
zze-MARCHEGAY Michael stagiaire FTRD/DTL/LAN wrote:
&gt; In fact, if an object 'a' contains an attribute 'b' that is another 
&gt; object, Oo.copy on 'a' gives a copy of 'a' in which the attribute
&gt; 'b' is **physically** equal to the copied attribute from 'a'.

I agree so far. But did you actually test the code below? I 
have reason to believe you are mistaken in believing that 
mutable fields are shared between Oo.copied objects, in such 
a way that assignment to such a field in one object will 
result in a modification in the value of the same field in 
all copies. I would consider such a behavior a major design 
flaw in the language.

The following toplevel session proves my point:

# class a i = object val mutable c = i method m = c &lt;- c + 1 
; print_string ((string_of_int c) ^ " ") end;;
class a : int -&gt; object method m : unit val mutable c : int end
# let a1 = new a 0;;
val a1 : a = &lt;obj&gt;
# let a2 = Oo.copy a1;;
val a2 : a = &lt;obj&gt;
# for i = 1 to 10 do a1 # m done;;
1 2 3 4 5 6 7 8 9 10 - : unit = ()
# for i = 1 to 15 do a2 # m done;;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 - : unit = ()
# for i = 11 to 15 do a1 # m done;;
11 12 13 14 15 - : unit = ()

Alex

&gt; Example:
&gt; class a = 
&gt;   object 
&gt;     val mutable b = new b
&gt;     method get_b = b
&gt;   end
&gt; and b = 
&gt;   object
&gt;     val mutable c = "1"
&gt;     method set_c x =  c &lt;- x
&gt;     method print_c = print_string ("c=" ^ c ^ "\n")  
&gt;   end
&gt; 
&gt; let aa = new a
&gt; let aa' = Oo.copy aa
&gt; 
&gt; let _ = 
&gt;   aa#get_b#set_c "3";
&gt;   aa#get_b#print_c;
&gt;   aa'#get_b#print_c
&gt; 
&gt; gives:
&gt; c=3
&gt; c=3
&gt; 
&gt; whereas a deep copy would give:
&gt; c=3
&gt; c=1

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners

</contents>

</message>

