Version française
Home     About     Download     Resources     Contact us    
Browse thread
Re: [Caml-list] help
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Jon Harrop <jdh30@c...>
Subject: Re: [Caml-list] help
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