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 MAA04913; Mon, 11 Jun 2001 12:21:02 +0200 (MET DST) 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 MAA05756 for ; Mon, 11 Jun 2001 12:21:01 +0200 (MET DST) Received: from ionie.inria.fr (ionie.inria.fr [128.93.39.12]) by concorde.inria.fr (8.11.1/8.10.0) with ESMTP id f5BAL1D23954 for ; Mon, 11 Jun 2001 12:21:01 +0200 (MET DST) Received: from ionie.inria.fr (localhost [127.0.0.1]) by ionie.inria.fr (8.11.1/8.10.0) with ESMTP id f5BAL0L08064 for ; Mon, 11 Jun 2001 12:21:00 +0200 (MET DST) Message-Id: <200106111021.f5BAL0L08064@ionie.inria.fr> X-Mailer: exmh version 2.1.1 10/15/1999 To: caml-list@inria.fr Subject: [Caml-list] where is my count: newbie's question Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Date: Mon, 11 Jun 2001 12:21:00 +0200 From: Francois Thomasset Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Sorry if this is a naive question, but I can't make out the reason of the behavior of the following function, which is a (seemingly!) slighty modification of the gensym example: # let fnx(x) = let count = ref 0 in let f() = Printf.printf "x = %d\n" x; Printf.printf "count = %d\n" !count; count := !count + 1; !count in f;; val fnx : int -> unit -> int = I would have expected that count remembers its previous value, which would be incremented at each call, but this is not true : !count is always 0. Of course if I remove the int argument I retrieve the behavior I expected: # let fnx = let count = ref 0 in let f() = Printf.printf "count = %d\n" !count; count := !count + 1; !count in f;; val fnx : unit -> int = # fnx();; count = 0 - : int = 1 # fnx();; count = 1 - : int = 2 François Thomasset. INRIA (A3) Tel: +33 (1) 39-63-54-75 Fax: +33 (1) 39-63-53-30 ou +33 (1) 39-63-59-95 Email: Francois.Thomasset@inria.fr Smail: INRIA, Rocquencourt, BP 105, 78153 Le Chesnay Cedex, France ------------------- 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