caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Nicolas FRANCOIS (AKA El Bofo) <nicolas.francois@free.fr>
To: Florian Hars <florian@hars.de>, Caml List <caml-list@inria.fr>
Subject: Re: [Caml-list] Side effect
Date: Fri, 9 Aug 2002 13:27:32 +0200	[thread overview]
Message-ID: <20020809132732.0139a7f4.nicolas.francois@free.fr> (raw)
In-Reply-To: <3D536483.4090103@hars.de>

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


  reply	other threads:[~2002-08-09 11:19 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-08-08 22:40 Nicolas FRANCOIS
2002-08-09  6:43 ` Florian Hars
2002-08-09 11:27   ` Nicolas FRANCOIS [this message]
2002-08-09 12:08     ` Pierre Weis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20020809132732.0139a7f4.nicolas.francois@free.fr \
    --to=nicolas.francois@free.fr \
    --cc=caml-list@inria.fr \
    --cc=florian@hars.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).