caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Re: [Caml-list] global record
@ 2006-07-19 17:14 Eric Breck
  2006-07-19 19:41 ` On language extensions (was Re: [Caml-list] global record) Daniel Bünzli
  0 siblings, 1 reply; 14+ messages in thread
From: Eric Breck @ 2006-07-19 17:14 UTC (permalink / raw)
  To: caml-list

[-- Attachment #1: Type: text/plain, Size: 3028 bytes --]


> Date: Wed, 19 Jul 2006 15:07:29 +0100
> From: Richard Jones <rich@annexia.org>
> Subject: Re: [Caml-list] global record
> To: Andreas Biegert <andreas.biegert@googlemail.com>
> Cc: caml-list@yquem.inria.fr

>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"

<gauche_self_promotion>

I was also writing code that looked like that, and I got tired of the
duplication, and also the non-locality - each new option requires a
modification in several places.  So the pa_arg syntax extension I just
announced makes this a lot easier.  Except for the reading of values from the
dotfile, all the above code is generated from this declaration (not tested):

open Parseopt

type option myopts = {
username = "" : help = "Adwords account username"; string;
password = "" : help = "Adwords account password";  string;
client: help = "Adwords account client (optional)"; string;
token = "": help = "Adwords account token"; string;
update = false: help = "Perform updates"; action = set; bool;
verbose = false: help = "Be verbose"; action = set; bool;
}
let myopts = {myopts with keyspecs = [Long2]} in (** specify you want field
foo => --foo *)

let options, args = parse_argv myopts in

...

if options.verbose then print "this is verbose mode!\n"

...

You also get a detailed usage and help message and a function to convert the
returned options to a string, plus further customizability.

http://www.cs.cornell.edu/~ebreck/pa_arg

-E r i c

</gauche_self_promotion>

[-- Attachment #2: Type: text/html, Size: 4376 bytes --]

^ permalink raw reply	[flat|nested] 14+ messages in thread
* global record
@ 2006-07-19 11:11 Andreas Biegert
  2006-07-19 11:42 ` [Caml-list] " Pietro Abate
                   ` (3 more replies)
  0 siblings, 4 replies; 14+ messages in thread
From: Andreas Biegert @ 2006-07-19 11:11 UTC (permalink / raw)
  To: caml-list

Hi,

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.

Andreas


^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2006-07-20  7:18 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-07-19 17:14 [Caml-list] global record Eric Breck
2006-07-19 19:41 ` On language extensions (was Re: [Caml-list] global record) Daniel Bünzli
2006-07-19 19:57   ` Richard Jones
2006-07-19 20:22     ` Stefano Zacchiroli
2006-07-19 21:33   ` Nicolas Pouillard
2006-07-20  2:57   ` Martin Jambon
  -- strict thread matches above, loose matches on Subject: below --
2006-07-19 11:11 global record Andreas Biegert
2006-07-19 11:42 ` [Caml-list] " Pietro Abate
     [not found] ` <3d13dcfc0607190528y624e5c9eg2c45e1cb17ec3771@mail.gmail.com>
2006-07-19 12:29   ` David MENTRE
2006-07-19 14:07 ` Richard Jones
2006-07-19 14:39   ` Yoann Padioleau
2006-07-19 14:50     ` Richard Jones
2006-07-19 15:09       ` Jean-Christophe Filliatre
2006-07-19 15:08     ` William D. Neumann
2006-07-20  7:26 ` Jeff Henrikson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).