[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: | 2002-08-09 (11:19) |
From: | Nicolas FRANCOIS <nicolas.francois@f...> |
Subject: | Re: [Caml-list] Side effect |
Le Fri, 09 Aug 2002 08:43:15 +0200 Florian Hars <florian@hars.de> a écrit : > Nicolas FRANCOIS (AKA El Bofo) wrote: > > So matrix m was modified. But I work on a copy of m in > > Pivot_Z.pivot_ligne_sans_echange. What's the problem doc ? > > Yes, m' is a copy of m, but the elements of m are arrays, so the copy m' > > contains references to the same arrays that m contains, so m.(i).(j) > is the same cell as m'.(i).(j). See: > > Objective Caml version 3.04 > > # let m = [|[|1;2|];[|3;4|]|];; > val m : int array array = [|[|1; 2|]; [|3; 4|]|] > # let m' = Array.copy m;; > val m' : int array array = [|[|1; 2|]; [|3; 4|]|] > # m'.(1).(1)<-99;; > - : unit = () > # m';; > - : int array array = [|[|1; 2|]; [|3; 99|]|] > # m;; > - : int array array = [|[|1; 2|]; [|3; 99|]|] > # m'.(1) <- [|0;0|];; > - : unit = () > # m' > ;; > - : int array array = [|[|1; 2|]; [|0; 0|]|] > # m;; > - : int array array = [|[|1; 2|]; [|3; 99|]|] > # > > Yours, Florian. Thanks, Florian. I guessed something like this, but could not find a clear explanation in the docs (not that the docs are bad, it's just the reader being unable to read it correctly). I'll have to write a matrix copy function :-) \bye -- Nicolas FRANCOIS http://nicolas.francois.free.fr A TRUE Klingon programmer does NOT comment his code ------------------- 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