From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id VAA23300; Mon, 15 Jul 2002 21:46:53 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id VAA23323 for ; Mon, 15 Jul 2002 21:46:52 +0200 (MET DST) X-SPAM-Warning: Sending machine is listed in blackholes.five-ten-sg.com Received: from athlon.baretta.com (r-mi214-6a227.tin.it [62.211.4.227]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g6FJkoj09098 for ; Mon, 15 Jul 2002 21:46:51 +0200 (MET DST) Received: from baretta.com (localhost.localdomain [127.0.0.1]) by athlon.baretta.com (Postfix) with ESMTP id 347262724F; Mon, 15 Jul 2002 21:53:53 +0200 (CEST) Message-ID: <3D332851.1080909@baretta.com> Date: Mon, 15 Jul 2002 21:53:53 +0200 From: Alessandro Baretta Organization: Baretta srl -- www.baretta.com User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0.0) Gecko/20020529 X-Accept-Language: it, en MIME-Version: 1.0 To: zze-MARCHEGAY Michael stagiaire FTRD/DTL/LAN , Ocaml Subject: Re: [Caml-list] Deep copy References: <0489A7888F080B4BA73B53F7E145F29A1B0AF5@LANMHS20.rd.francetelecom.fr> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk zze-MARCHEGAY Michael stagiaire FTRD/DTL/LAN wrote: > In fact, if an object 'a' contains an attribute 'b' that is another > object, Oo.copy on 'a' gives a copy of 'a' in which the attribute > '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 <- c + 1 ; print_string ((string_of_int c) ^ " ") end;; class a : int -> object method m : unit val mutable c : int end # let a1 = new a 0;; val a1 : a = # let a2 = Oo.copy a1;; val a2 : a = # 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 > Example: > class a = > object > val mutable b = new b > method get_b = b > end > and b = > object > val mutable c = "1" > method set_c x = c <- x > method print_c = print_string ("c=" ^ c ^ "\n") > end > > let aa = new a > let aa' = Oo.copy aa > > let _ = > aa#get_b#set_c "3"; > aa#get_b#print_c; > aa'#get_b#print_c > > gives: > c=3 > c=3 > > whereas a deep copy would give: > c=3 > 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