Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: John Prevost <j.prevost@gmail.com>
To: caml-list@inria.fr,
	Thomas Fischbacher <thomas.fischbacher@physik.uni-muenchen.de>
Subject: Re: [Caml-list] Arg parsing
Date: Wed, 27 Oct 2004 18:13:15 -0400	[thread overview]
Message-ID: <d849ad2a04102715138f2f1e4@mail.gmail.com> (raw)
In-Reply-To: <Pine.LNX.4.58.0410272015430.20206@eiger.cip.physik.uni-muenchen.de>

On Wed, 27 Oct 2004 20:17:05 +0200 (CEST), Thomas Fischbacher
<thomas.fischbacher@physik.uni-muenchen.de> wrote:
> That's not what I mean. I want to be able to start "ocaml" in such a way
> that I get the toplevel, but can #use code which parses the args that were
> given originally to ocaml.

The following works just fine for me:

----------
#!/usr/bin/env ocaml

let _ = begin
  let arg_count = Array.length Sys.argv in
  Printf.printf "%s: received %d arguments\n" Sys.argv.(0) (arg_count - 1);
  for i = 1 to arg_count - 1 do
    Printf.printf "%2d: %s\n" i Sys.argv.(i)
  done
end
----------

$ ocaml test.ml a b c
test.ml: received 3 arguments
 1: a
 2: b
 3: c

$ ./test.ml a b c d e f g h
./test.ml: received 8 arguments
 1: a
 2: b
 3: c
 4: d
 5: e
 6: f
 7: g
 8: h


The above works as long as you don't also want to give arguments to
ocaml itself.  If you want to do that, you may need a hack like the
following:

------------
#!/bin/sh
#labels true;; (*
exec ocaml -dparsetree $0 $*
# *)

let _ = begin
  let arg_count = Array.length Sys.argv in
  Printf.printf "%s: received %d arguments\n" Sys.argv.(0) (arg_count - 1);
  for i = 1 to arg_count - 1 do
    Printf.printf "%2d: %s\n" i Sys.argv.(i)
  done
end
------------

I'm not sure why you'd want to do that, though.  The only useful
argument that can't be duplicated with a #blah directive is "-unsafe".

John.


  reply	other threads:[~2004-10-27 22:13 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-10-26 19:56 Thomas Fischbacher
2004-10-26 20:13 ` [Caml-list] " William Lovas
2004-10-27 18:17   ` Thomas Fischbacher
2004-10-27 22:13     ` John Prevost [this message]
2004-10-28 12:44       ` Thomas Fischbacher
2004-10-28 14:56         ` John Prevost
2004-11-04 14:42           ` Thomas Fischbacher
2004-11-04 15:28             ` John Prevost
2004-11-04 20:40               ` Thomas Fischbacher
2004-10-26 21:05 ` Problem with location sejourne_kevin
2004-10-26 21:36   ` [Caml-list] " Tiago Dionizio
2004-10-26 22:33     ` Matt Gushee

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=d849ad2a04102715138f2f1e4@mail.gmail.com \
    --to=j.prevost@gmail.com \
    --cc=caml-list@inria.fr \
    --cc=thomas.fischbacher@physik.uni-muenchen.de \
    /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