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 GAA06632; Wed, 19 Jun 2002 06:39:00 +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 GAA06605 for ; Wed, 19 Jun 2002 06:38:59 +0200 (MET DST) Received: from web10705.mail.yahoo.com (web10705.mail.yahoo.com [216.136.130.213]) by nez-perce.inria.fr (8.11.1/8.11.1) with SMTP id g5J4cvj12886 for ; Wed, 19 Jun 2002 06:38:58 +0200 (MET DST) Message-ID: <20020619043857.22458.qmail@web10705.mail.yahoo.com> Received: from [64.255.66.233] by web10705.mail.yahoo.com via HTTP; Tue, 18 Jun 2002 21:38:57 PDT Date: Tue, 18 Jun 2002 21:38:57 -0700 (PDT) From: Shannon --jj Behrens Subject: Re: [Caml-list] static variables in a function To: caml-list@inria.fr In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk For any of you that are interested, here's the code (based on a combination of your comments). This code has the following benefits: 1) The calling functions don't need to deal with passing in a ref []. 2) Multiple "instances" of this function can be used independently. 3) Only one match clause is needed, so there is no repeated code (in my case, an exception will be thrown for EOF). (* * Return a function that has the interface of a * lexer and can act as a token buffer. *) let get_token_buffer () = let token_list = ref [] in let rec get_token token_list () = match !token_list with head :: tail -> token_list := tail; head | [] -> token_list := [1; 2; 3]; (* replace me *) get_token token_list () in get_token token_list;; (* Try it out. *) let token_buffer = get_token_buffer () in while true do print_int (token_buffer ()) done __________________________________________________ Do You Yahoo!? Yahoo! - Official partner of 2002 FIFA World Cup http://fifaworldcup.yahoo.com ------------------- 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