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 TAA10371; Sun, 25 Apr 2004 19:10:19 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id TAA09807 for ; Sun, 25 Apr 2004 19:10:18 +0200 (MET DST) Received: from ptb-relay03.plus.net (ptb-relay03.plus.net [212.159.14.214]) by nez-perce.inria.fr (8.12.10/8.12.10) with ESMTP id i3PHAHjq005593 for ; Sun, 25 Apr 2004 19:10:17 +0200 Received: from [80.229.56.224] (helo=chetara) by ptb-relay03.plus.net with esmtp (Exim) id 1BHn8y-000MYx-7e for caml-list@inria.fr; Sun, 25 Apr 2004 17:10:16 +0000 From: Jon Harrop Organization: University of Cambridge To: caml-list@inria.fr Subject: Re: [Caml-list] help Date: Sun, 25 Apr 2004 18:06:23 +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: <200404251806.23130.jdh30@cam.ac.uk> X-Miltered: at nez-perce 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 model:01 val:01 model:01 mutable:01 int:01 wrote:03 let:04 array:04 array:04 init:05 init:05 structure:06 cheers:06 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Sunday 25 April 2004 5:30 pm, mohammad siddiqui wrote: > I tried exactly what you have told. Its is fine when we just have one > element in an array of words. If we have more than one, changing the value > of one changes the values of the rest of the elements. Sorry, yes. Now I come to think of it, it's kind of obvious that a mutable field in a record would also get copied. My fault. So we don't want to use Array.make to generate this structure... How about using Array.init? This function takes the size of the array and a function which generates an element in the array given the index of the element within the array, e.g.: # Array.init 4 (fun i -> i*i);; - : int array = [|0; 1; 4; 9|] So we get: let test_model = { sv_num=0; at_upper_bound=0; b=0.; supvec=Array.init 4 (fun i -> { docnum=0; queryid=0; costfactor=0.; twonorm_sq=0.; words=[| { wnum=ref (i*i); weight=0. } |] }); alpha=0. };; val test_model : model = {sv_num = 0; at_upper_bound = 0; b = 0.; supvec = [|{docnum = 0; queryid = 0; costfactor = 0.; twonorm_sq = 0.; words = [|{wnum = {contents = 0}; weight = 0.}|]}; {docnum = 0; queryid = 0; costfactor = 0.; twonorm_sq = 0.; words = [|{wnum = {contents = 1}; weight = 0.}|]}; {docnum = 0; queryid = 0; costfactor = 0.; twonorm_sq = 0.; words = [|{wnum = {contents = 4}; weight = 0.}|]}; {docnum = 0; queryid = 0; costfactor = 0.; twonorm_sq = 0.; words = [|{wnum = {contents = 9}; weight = 0.}|]}|]; alpha = 0.} HTH! 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