From: Christophe Delage <cdelage@ens-lyon.fr>
To: "caml-list@inria.fr" <caml-list@inria.fr>
Subject: Re: [Caml-list] Newbie q. about Arg parsing
Date: Sat, 17 Aug 2002 17:32:32 +0200 (MEST) [thread overview]
Message-ID: <Pine.GSO.4.21.0208171623380.29646-100000@ponant> (raw)
In-Reply-To: <3D5E1DD3.7CAF4F5E@ngi.de>
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
next prev parent reply other threads:[~2002-08-17 15:32 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-08-17 9:56 Gerald heinig
2002-08-17 15:32 ` Christophe Delage [this message]
2002-08-19 16:42 ` Florian Hars
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Pine.GSO.4.21.0208171623380.29646-100000@ponant \
--to=cdelage@ens-lyon.fr \
--cc=caml-list@inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox