[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: | 2002-08-17 (15:32) |
From: | Christophe Delage <cdelage@e...> |
Subject: | Re: [Caml-list] Newbie q. about Arg parsing |
On Sat, 17 Aug 2002, Gerald heinig wrote: > Hi all, Hi, > Can you use Arg to parse the command line in purely functional style? If > yes, how? Well, Arg.parse expects functions of type string -> unit, int -> unit, etc. and calls theses functions when it finds the corresponding argument. This is a purely imperative behaviour, I am afraid that doing something usefull with Arg.parse leads to some side effects. The simplest idea I see is to keep a reference to the integer you want to pass to fnamefun, and setting it when you see a "-s": let main = let lineno = ref 0 in (* or any other default value *) let call_fname filename = (* call fnamefun with the right args *) fnamefun filename !lineno in Arg.parse [ "-s", (fun i -> intarg := i), "linenumber"; "-", call_fname, "filename" ] call_fname "usage" (assuming that fnamefun takes two arguments : the filename and the lineno) Hope this helps, Christophe ------------------- 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