From: hubert.fauque@wanadoo.fr
To: caml <caml-list@inria.fr>
Subject: Re: [Caml-list] Question sur les références.
Date: 28 Dec 2001 16:36:01 +0100 [thread overview]
Message-ID: <87vger1hni.fsf@debian.castelnau.fr> (raw)
In-Reply-To: <3C2C7FC9.86AD1CA3@free.fr>
English summary follows
WatchDog <watchdog@free.fr> writes:
> Bonjour ! Cette petite fonction me pose des problèmes :
>
> let resultat (a,b,c,d) position =
> let pos=ref position in
> !pos.(d).(c) <- !pos.(b).(a) ; !pos.(b).(a) <- V ;
> !pos ;;
>
> Quel ne fut pas mon étonnement en constatant que cette fonction se
> permettait de modifier le contenu même de position, alors que je ne l'ai
> utilisé qu'avec une référence (pos) qui pointait dessus !
> Quand on écrit
> let x = ref 1 in x := !x + 1;;
> ça ne modifie pas la valeur de l'entier 1, non ???
> Merci de votre éclairage.
pos est une référence sur position ce qui veut dire que
!pos est égal à position; donc faire
!pos.(d).(c) <- !pos.(b).(a) ; !pos.(b).(a) <- V ;
est identique à faire
position.(d).(c) <- position.(b).(a) ; position.(b).(a) <- V ;
ce que vous voulez faire en fait est une copie du tableau
ce qui se fait pour un tableau simple avec Array.copy,
mais comme ici c'est une matrice faire Array.copy ne
copiera qu'un niveau de la structure du tableau; il faut donc
faire:
let pos = Array.map Array.copy position in
pos.(d).(c) <- pos.(b).(a) ; pos.(b).(a) <- V ;
taking a ref on an array does not create a new array;
it is necessary to use Array.copy and in case of a matrix
(Array.map Array.copy)
Hubert Fauque
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
next prev parent reply other threads:[~2001-12-28 15:37 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-12-28 14:20 WatchDog
2001-12-28 15:36 ` hubert.fauque [this message]
2001-12-28 16:18 ` WatchDog
2001-12-28 17:27 ` hubert.fauque
2001-12-29 16:54 ` [Caml-list] lablGL and GLUT Christophe Raffalli
2001-12-30 8:15 ` [Caml-list] Re: [Caml-list] Question sur les références Alan Schmitt
2001-12-30 11:05 ` Daniel de Rauglaudre
2002-01-01 11:20 ` [Caml-list] " Alan Schmitt
2001-12-28 15:45 ` Daniel de Rauglaudre
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=87vger1hni.fsf@debian.castelnau.fr \
--to=hubert.fauque@wanadoo.fr \
--cc=caml-list@inria.fr \
/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