* 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; 9+ 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] 9+ messages in thread
* Re: [Caml-list] global record 2006-07-19 11:11 global record Andreas Biegert @ 2006-07-19 11:42 ` Pietro Abate [not found] ` <3d13dcfc0607190528y624e5c9eg2c45e1cb17ec3771@mail.gmail.com> ` (2 subsequent siblings) 3 siblings, 0 replies; 9+ messages in thread From: Pietro Abate @ 2006-07-19 11:42 UTC (permalink / raw) To: caml-list On Wed, Jul 19, 2006 at 01:11:22PM +0200, Andreas Biegert wrote: > 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. For my application I've a module where each runtime option is a ref and then I use the Arg module to set the proper value. Don't know if there are better way of doing this... :) p -- ++ Blog: http://blog.rsise.anu.edu.au/?q=pietro ++ ++ "All great truths begin as blasphemies." -George Bernard Shaw ++ Please avoid sending me Word or PowerPoint attachments. See http://www.fsf.org/philosophy/no-word-attachments.html ^ permalink raw reply [flat|nested] 9+ messages in thread
[parent not found: <3d13dcfc0607190528y624e5c9eg2c45e1cb17ec3771@mail.gmail.com>]
* Re: [Caml-list] global record [not found] ` <3d13dcfc0607190528y624e5c9eg2c45e1cb17ec3771@mail.gmail.com> @ 2006-07-19 12:29 ` David MENTRE 0 siblings, 0 replies; 9+ messages in thread From: David MENTRE @ 2006-07-19 12:29 UTC (permalink / raw) To: Ocaml Oops, forgot the caml-list. d. 2006/7/19, David MENTRE <david.mentre@gmail.com>: > Hello, > > 2006/7/19, Andreas Biegert <andreas.biegert@googlemail.com>: > > Is > > there a way to make the (possibly modified) parameters record globally > > accessable throughout all modules? > > Define a global variable in the Par module, use it in the other modules. > > ==par.ml== > type param = { mutable a: int; } > > let params = { a = 3; } > == > > ==foo.ml== > let bar = Par.params.a > > let _ = Par.params.a <- bar + 1 > == > > > This would be much more convenient > > than having to pass the parameters record to virtually all functions > > in my application. > > <personal taste>I find this purely functional approach much cleaner > because you know where your global variables are read or modified > directly by looking at function parameters.</personal taste> > > Best wishes, > d. > ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [Caml-list] global record 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 14:07 ` Richard Jones 2006-07-19 14:39 ` Yoann Padioleau 2006-07-20 7:26 ` Jeff Henrikson 3 siblings, 1 reply; 9+ messages in thread From: Richard Jones @ 2006-07-19 14:07 UTC (permalink / raw) To: Andreas Biegert; +Cc: caml-list 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 ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [Caml-list] global record 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:08 ` William D. Neumann 0 siblings, 2 replies; 9+ messages in thread From: Yoann Padioleau @ 2006-07-19 14:39 UTC (permalink / raw) To: Richard Jones; +Cc: Andreas Biegert, caml-list Richard Jones <rich@annexia.org> writes: > 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 You certainly mean val username: string ref > 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 [] > [ ... ] > > Then the code just stuff like: > > open Stdargs > > if verbose then printf "this is verbose mode\n" You certainly mean if !verbose then printf "this is verbose mode\n" > > Rich. -- pad ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [Caml-list] global record 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 1 sibling, 1 reply; 9+ messages in thread From: Richard Jones @ 2006-07-19 14:50 UTC (permalink / raw) To: Yoann Padioleau; +Cc: Andreas Biegert, caml-list On Wed, Jul 19, 2006 at 04:39:32PM +0200, Yoann Padioleau wrote: > Richard Jones <rich@annexia.org> writes: > > val username : string > > You certainly mean > val username: string ref No, I mean: val username : string 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 ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [Caml-list] global record 2006-07-19 14:50 ` Richard Jones @ 2006-07-19 15:09 ` Jean-Christophe Filliatre 0 siblings, 0 replies; 9+ messages in thread From: Jean-Christophe Filliatre @ 2006-07-19 15:09 UTC (permalink / raw) To: Richard Jones; +Cc: Yoann Padioleau, caml-list, Andreas Biegert Richard Jones writes: > On Wed, Jul 19, 2006 at 04:39:32PM +0200, Yoann Padioleau wrote: > > Richard Jones <rich@annexia.org> writes: > > > val username : string > > > > You certainly mean > > val username: string ref > > No, I mean: > > val username : string and I confirm :-) I use the same trick of dereferencing the references used for command-line parsing as soon as it is done and I find this very convenient. This can be realized in the very first module on your ocaml link command, and thus in whole the remaining of your code you do not need to use the deref operator (!) anymore. -- Jean-Christophe ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [Caml-list] global record 2006-07-19 14:39 ` Yoann Padioleau 2006-07-19 14:50 ` Richard Jones @ 2006-07-19 15:08 ` William D. Neumann 1 sibling, 0 replies; 9+ messages in thread From: William D. Neumann @ 2006-07-19 15:08 UTC (permalink / raw) To: Yoann Padioleau; +Cc: Richard Jones, caml-list, Andreas Biegert On Wed, 19 Jul 2006, Yoann Padioleau wrote: > You certainly mean > > if !verbose then printf "this is verbose mode\n" No. After he calls Arg parse, he does: 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 and loses the refs. William D. Neumann --- "There's just so many extra children, we could just feed the children to these tigers. We don't need them, we're not doing anything with them. Tigers are noble and sleek; children are loud and messy." -- Neko Case Life is unfair. Kill yourself or get over it. -- Black Box Recorder ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [Caml-list] global record 2006-07-19 11:11 global record Andreas Biegert ` (2 preceding siblings ...) 2006-07-19 14:07 ` Richard Jones @ 2006-07-20 7:26 ` Jeff Henrikson 3 siblings, 0 replies; 9+ messages in thread From: Jeff Henrikson @ 2006-07-20 7:26 UTC (permalink / raw) To: Andreas Biegert; +Cc: caml-list The full generalization of this is dynamic scoping, as you may know. There's a discussion of the implementation in emacs in the emacs manual. Not thread safe but can be made so with an immutable binary tree, eg the Map module. You could map either strings or polymorphic variants to your config value type, probably a regular variant. I'm not sure how much of a performance savings polymoprhic variants would be over strings. For a couple of other approaches see http://caml.inria.fr/pub/ml-archives/caml-list/2004/12/a0924032de03d517cb8cb8f2adde6c94.en.html Jeff Andreas Biegert wrote: > 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 > > _______________________________________________ > Caml-list mailing list. Subscription management: > http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list > Archives: http://caml.inria.fr > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs ^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2006-07-20 7:18 UTC | newest] Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 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