From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id F0300BB83 for ; Wed, 19 Jul 2006 16:08:09 +0200 (CEST) Received: from furbychan.cocan.org (furbychan.cocan.org [80.68.91.176]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id k6JE84IW017823 (version=TLSv1/SSLv3 cipher=EDH-RSA-DES-CBC3-SHA bits=168 verify=NO) for ; Wed, 19 Jul 2006 16:08:09 +0200 Received: from rich by furbychan.cocan.org with local (Exim 3.35 #1 (Debian)) id 1G3Ci1-0007zi-00; Wed, 19 Jul 2006 15:07:29 +0100 Date: Wed, 19 Jul 2006 15:07:29 +0100 To: Andreas Biegert Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] global record Message-ID: <20060719140729.GA26227@furbychan.cocan.org> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.9i From: Richard Jones X-Miltered: at concorde with ID 44BE3CC4.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; overwritten:01 command-line:01 api:01 mli:01 val:01 val:01 bool:01 verbose:01 bool:01 verbose:01 omitted:01 printf:01 notepad:01 2006:98 wrote:01 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.3 On Wed, Jul 19, 2006 at 01:11:22PM +0200, Andreas Biegert wrote: > I am developing a bioinformatics sequence analysis application which > contains about 20 modules. One of those modules, the 'Par' module, > encapsulates a record of about 30 configuration parameters needed > throughout the whole application. The parameter record is mostly > static but some values can be overwritten by command-line options. Is > there a way to make the (possibly modified) parameters record globally > accessable throughout all modules? This would be much more convenient > than having to pass the parameters record to virtually all functions > in my application. THX for helping. This is a bit ugly, but we use it in our Adwords API toolkit: -------------------------------------------------- stdargs.mli val username : string val password : string val client : string option val token : string val update : bool val verbose : bool val args : string list -------------------------------------------------- stdargs.ml let username = ref "" let password = ref "" let client = ref "" let token = ref "" let update = ref false let verbose = ref false let args = ref [] (* followed by some code which tries to read default values * from $HOME/.adwordsapidata -- code omitted *) (* parse the command line parameters *) let argspec = [ "--username", Arg.Set_string username, "Adwords account username."; "--password", Arg.Set_string password, "Adwords account password."; "--client", Arg.Set_string client, "Adwords account client (optional)."; "--token", Arg.Set_string token, "Adwords account token."; "--update", Arg.Set update, "Perform updates."; "--verbose", Arg.Set verbose, "Be verbose."; ] let anon_fn str = args := str :: !args let usage = Sys.executable_name ^ " [--options]" let () = Arg.parse argspec anon_fn usage let username = !username let password = !password let client = if !client = "" then None else Some !client let token = !token let update = !update let verbose = !verbose let args = List.rev !args --- Then the code just stuff like: open Stdargs if verbose then printf "this is verbose mode\n" Rich. -- Richard Jones, CTO Merjis Ltd. Merjis - web marketing and technology - http://merjis.com Team Notepad - intranets and extranets for business - http://team-notepad.com