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 XAA07244; Tue, 23 Oct 2001 23:41:39 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id XAA07314 for ; Tue, 23 Oct 2001 23:41:38 +0200 (MET DST) Received: from apeiba.wanadoo.fr (smtp-rt-2.wanadoo.fr [193.252.19.154]) by nez-perce.inria.fr (8.11.1/8.10.0) with ESMTP id f9NLfbT18079 for ; Tue, 23 Oct 2001 23:41:37 +0200 (MET DST) Received: from mel-rta7.wanadoo.fr (193.252.19.61) by apeiba.wanadoo.fr; 23 Oct 2001 23:41:37 +0200 Received: from imag.fr (217.128.202.61) by mel-rta7.wanadoo.fr; 23 Oct 2001 23:41:01 +0200 Message-ID: <3BD5E5EF.DA701A11@imag.fr> Date: Tue, 23 Oct 2001 23:49:35 +0200 From: Michel Levy X-Mailer: Mozilla 4.77 [fr] (X11; U; Linux 2.4.5 i686) X-Accept-Language: en MIME-Version: 1.0 To: caml-list@inria.fr Subject: [Caml-list] surprising program Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk I don't understand the behavior of the following program (ocaml 3.01) type couple = {p1 :int ;p2:int};; let c1 = {p1=0;p2=10};; let c2 = {p1=0;p2 = 20};; let n = ref 0;; let rec numero l = match l with | [] -> [] | t::f ->n:=!n+1; {t with p1= !n }::numero f;; (* # numero [c1;c2];; - : couple list = [{p1=2; p2=10}; {p1=2; p2=20}] *) Why the fied p1 has the value 2 ? Why it's different with the fonction numero' let n' = ref 0;; let rec numero' l = match l with | [] -> [] | t::f -> n':=!n'+1; let a = !n' in {t with p1= a }::numero' f;; (* # numero' [c1;c2];; - : couple list = [{p1=1; p2=10}; {p1=2; p2=20}] *) Thank you really much for any explanation. -- Michel Levy 36 rue George Sand 38400 Saint Martin d'Hères email : Michel.Levy@imag.fr http://www-lsr.imag.fr/users/Michel.Levy/ ------------------- 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