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 RAA08127; Sat, 17 Aug 2002 17:32:38 +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 RAA08126 for ; Sat, 17 Aug 2002 17:32:38 +0200 (MET DST) Received: from mailhost.ens-lyon.fr (pluvier.ens-lyon.fr [140.77.167.5]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id g7HFWYj06860 for ; Sat, 17 Aug 2002 17:32:35 +0200 (MET DST) Received: from ponant.ens-lyon.fr ([140.77.191.80] helo=ponant) by mailhost.ens-lyon.fr with esmtp (Exim 3.35 #1 (Debian)) id 17g5Z2-0006D0-00 for ; Sat, 17 Aug 2002 17:32:32 +0200 Date: Sat, 17 Aug 2002 17:32:32 +0200 (MEST) From: Christophe Delage X-Sender: cdelage@ponant To: "caml-list@inria.fr" Subject: Re: [Caml-list] Newbie q. about Arg parsing In-Reply-To: <3D5E1DD3.7CAF4F5E@ngi.de> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk 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