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 IAA32278; Sat, 15 Jun 2002 08:30:30 +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 IAA32244 for ; Sat, 15 Jun 2002 08:30:28 +0200 (MET DST) Received: from laurelin.dementia.org ([208.167.88.73]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id g5F6UR512380 for ; Sat, 15 Jun 2002 08:30:27 +0200 (MET DST) Received: by laurelin.dementia.org (Postfix, from userid 1001) id B95BD70B9; Sat, 15 Jun 2002 02:36:03 -0400 (EDT) To: Max Kirillov Cc: caml-list@inria.fr Subject: Re: [Caml-list] static variables in a function References: <20020614170830.28193.qmail@web10705.mail.yahoo.com> <20020615114201.B1425@max.home> From: John Prevost Date: 15 Jun 2002 02:36:03 -0400 In-Reply-To: <20020615114201.B1425@max.home> Message-ID: <864rg5oxpo.fsf@laurelin.dementia.org> User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk >>>>> "mk" == Max Kirillov writes: mk> Hello. The code you write will generate a new (empty) ref at mk> every call. Actually, it won't. Take a look at the code that was sent by Yutaka OIWA: let get_chunk = let chunks_list = ref [] in fun () -> ... The ref is bound outside of the function definition, so it's created once and kept in the closure, not allocated in each call. If it were written this way: let get_chunk () = let chunks_list = ref [] in ... or equivalently: let get_chunk = fun () -> let chunks_list = ref [] in ... it would be created separately for each call. But the way it was originally written is correct. Your version also works, but creates a module-level binding for the value as well, which isn't desirable for something like this, where you want the value to be local to the function definition. John. ------------------- 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