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 GAA06682; Fri, 23 Apr 2004 06:43:57 +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 GAA06927 for ; Fri, 23 Apr 2004 06:43:57 +0200 (MET DST) Received: from ptb-relay03.plus.net (ptb-relay03.plus.net [212.159.14.214]) by concorde.inria.fr (8.12.10/8.12.10) with ESMTP id i3N4huYM027521 for ; Fri, 23 Apr 2004 06:43:56 +0200 Received: from [80.229.56.224] (helo=chetara) by ptb-relay03.plus.net with esmtp (Exim) id 1BGsXa-00004m-NA for caml-list@inria.fr; Fri, 23 Apr 2004 04:43:54 +0000 From: Jon Harrop Organization: University of Cambridge To: caml-list@inria.fr Subject: Re: [Caml-list] help Date: Fri, 23 Apr 2004 05:17:59 +0100 User-Agent: KMail/1.5.4 References: In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200404230517.59319.jdh30@cam.ac.uk> X-Miltered: at concorde by Joe's j-chkmail ("http://j-chkmail.ensmp.fr")! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 2004:99 initialized:01 predicate:01 indirection:01 mutable:01 mutable:01 int:01 external:03 wrote:03 interface:03 btw:03 sys:03 sys:03 argument:03 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Friday 23 April 2004 3:31 am, mohammad siddiqui wrote: > I already made it mutable. words is an array of structure called "word". > If I try to change the value as you told it changes tha values of all the > elements of array "words". Thanks for your help in advance. > > Mohammad S Siddiqui. I haven't actually done that sort of thing myself but asking ocamlbrowser for the interface information on Array.make gives: >>>>> external make : int -> 'a -> 'a array = "make_vect" (** [Array.make n x] returns a fresh array of length [n], initialized with [x]. All the elements of this new array are initially physically equal to [x] (in the sense of the [==] predicate). Consequently, if [x] is mutable, it is shared among all elements of the array, and modifying [x] through one of the array entries will modify all other entries at the same time. Raise [Invalid_argument] if [n < 0] or [n > Sys.max_array_length]. If the value of [x] is a floating-point number, then the maximum size is only [Sys.max_array_length / 2].*) <<<<< "Array.create" is a depricated alias for "Array.make", BTW. So if you're using either "Array.make" or "Array.create" to build your array then you're creating an array filled with references to the same thing. Does that answer your question? Personally, I tend to build up a list and then convert it into an array using "Array.of_list". I guess the question is: are you creating an unecessary level of indirection by making the type of the elements in your array mutable when an array element is itself already mutable? If you're still having trouble with your data structures then I'll run through it with you off the mailing list... Cheers, Jon. ------------------- 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