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 AAA29451; Sun, 16 Feb 2003 00:10:45 +0100 (MET) 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 AAA29447 for ; Sun, 16 Feb 2003 00:10:44 +0100 (MET) Received: from mailhost.ens-lyon.fr (pluvier.ens-lyon.fr [140.77.167.5]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id h1FNAif11768 for ; Sun, 16 Feb 2003 00:10:44 +0100 (MET) Received: from babasse.residence.ens-lyon.fr ([140.77.128.220] helo=Babasse) by mailhost.ens-lyon.fr with smtp (Exim 3.35 #1 (Debian)) id 18kBSF-0006VM-00; Sun, 16 Feb 2003 00:10:43 +0100 Date: Sun, 16 Feb 2003 00:07:42 +0100 From: Samuel Mimram To: WatchDog Cc: caml-list@inria.fr Subject: Re: [Caml-list] Problem in modifying a mutable element in an array Message-Id: <20030216000742.3376f3bc.Samuel.Mimram@ens-lyon.fr> In-Reply-To: <3E4EC399.20200@free.fr> References: <3E4EC399.20200@free.fr> X-Mailer: Sylpheed version 0.8.10claws13 (GTK+ 1.2.10; i386-debian-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Hello, Your "problem" is due to the fact that when you use the function make_vect = m agent_init, Caml creates an array where all element are pointing at the s= ame object which is agent_init : in your whole program, there is only one i= nstance of agent_init in memory. I think that the only solution is to make the initilization of f by hand : let agent_init () =3D { initial =3D 0 ; courant =3D 0 ; longueur =3D 0.; li= ste_parcourue =3D [] ; =E0_visiter =3D make_vect n 1 } ;; let f =3D make_vect m (agent_init ());; for i =3D 0 to ((vect_length f)-1) do f.(i) <- agent_init () done The use of a function which takes a unit argument is important because each= time you call it, it returns a NEW record. I hope this helps. Samuel. On Sat, 15 Feb 2003 23:47:53 +0100 WatchDog wrote: > Hello ! > My problem has first appeared in a CamlLight implementation, but I have=20 > then tried to do the same on O'Caml and the problem remained equal. But=20 > I'm sure you'll be able to provide some help, won't you ? > In Caml Light : >=20 > #open "random";; > type agent =3D { mutable initial : int ; mutable courant : int ; > mutable longueur : float ; mutable liste_parcourue : int=20 > list ; > =E0_visiter : int vect } ;; > let agent_init =3D { initial =3D 0 ; courant =3D 0 ; longueur =3D 0. ;=20 > liste_parcourue =3D [] ; > =E0_visiter =3D make_vect n 1 } ;; > let f =3D make_vect m agent_init ;; > =20 > let set_f () =3D for p =3D 0 to (m-1) do > begin =20 > f.(p).initial <- (int n) ; > f.(p).courant <- (int n) ; > f.(p).liste_parcourue <- [(int n)] ; > f.(p).=E0_visiter.(int n) <- 0 > end > done > ;; >=20 >=20 > And then set_f() doesn't work properly : it seems Caml refuses to modify= =20 > one element (for instance f.(5).initial) without modifying automatically= =20 > all its brothers, e.g. all the f.(i).initial ; for i from 0 to (m-1). > The fact is that I'd like to modify it element-by-element, and not all=20 > at the same time. >=20 > Your help would be a real relief !! > Thanks >=20 > JB, from Paris. >=20 > ------------------- > To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inr= ia.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 --=20 Samuel Mimram Samuel.Mimram@ens-lyon.fr ------------------- 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