* Arg parsing
@ 2004-10-26 19:56 Thomas Fischbacher
2004-10-26 20:13 ` [Caml-list] " William Lovas
2004-10-26 21:05 ` Problem with location sejourne_kevin
0 siblings, 2 replies; 12+ messages in thread
From: Thomas Fischbacher @ 2004-10-26 19:56 UTC (permalink / raw)
To: caml-list
I think it would be helpful if ocaml had an '--' arg that tells it to stop
its own arg parsing and pass the following args on to the program started,
as in:
tf@ouija:~$ perl -e 'print @ARGV' -- one tooth ree
onetoothree
--
regards, tf@cip.physik.uni-muenchen.de (o_
Thomas Fischbacher - http://www.cip.physik.uni-muenchen.de/~tf //\
(lambda (n) ((lambda (p q r) (p p q r)) (lambda (g x y) V_/_
(if (= x 0) y (g g (- x 1) (* x y)))) n 1)) (Debian GNU)
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Caml-list] Arg parsing
2004-10-26 19:56 Arg parsing Thomas Fischbacher
@ 2004-10-26 20:13 ` William Lovas
2004-10-27 18:17 ` Thomas Fischbacher
2004-10-26 21:05 ` Problem with location sejourne_kevin
1 sibling, 1 reply; 12+ messages in thread
From: William Lovas @ 2004-10-26 20:13 UTC (permalink / raw)
To: caml-list
Hi Thomas,
On Tue, Oct 26, 2004 at 09:56:30PM +0200, Thomas Fischbacher wrote:
>
> I think it would be helpful if ocaml had an '--' arg that tells it to stop
> its own arg parsing and pass the following args on to the program started,
> as in:
>
> tf@ouija:~$ perl -e 'print @ARGV' -- one tooth ree
> onetoothree
You can do this with the standard Arg module. For example:
Arg.parse [...; ("--", Arg.Rest anon_fun, " stop parsing options")]
anon_fun
usage_msg
See the Arg module's documentation for details.
cheers,
William
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Caml-list] Arg parsing
2004-10-26 20:13 ` [Caml-list] " William Lovas
@ 2004-10-27 18:17 ` Thomas Fischbacher
2004-10-27 22:13 ` John Prevost
0 siblings, 1 reply; 12+ messages in thread
From: Thomas Fischbacher @ 2004-10-27 18:17 UTC (permalink / raw)
To: William Lovas; +Cc: caml-list
On Tue, 26 Oct 2004, William Lovas wrote:
> You can do this with the standard Arg module. For example:
>
> Arg.parse [...; ("--", Arg.Rest anon_fun, " stop parsing options")]
> anon_fun
> usage_msg
>
> See the Arg module's documentation for details.
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.
--
regards, tf@cip.physik.uni-muenchen.de (o_
Thomas Fischbacher - http://www.cip.physik.uni-muenchen.de/~tf //\
(lambda (n) ((lambda (p q r) (p p q r)) (lambda (g x y) V_/_
(if (= x 0) y (g g (- x 1) (* x y)))) n 1)) (Debian GNU)
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Caml-list] Arg parsing
2004-10-27 18:17 ` Thomas Fischbacher
@ 2004-10-27 22:13 ` John Prevost
2004-10-28 12:44 ` Thomas Fischbacher
0 siblings, 1 reply; 12+ messages in thread
From: John Prevost @ 2004-10-27 22:13 UTC (permalink / raw)
To: caml-list, Thomas Fischbacher
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.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Caml-list] Arg parsing
2004-10-27 22:13 ` John Prevost
@ 2004-10-28 12:44 ` Thomas Fischbacher
2004-10-28 14:56 ` John Prevost
0 siblings, 1 reply; 12+ messages in thread
From: Thomas Fischbacher @ 2004-10-28 12:44 UTC (permalink / raw)
To: John Prevost; +Cc: caml-list
On Wed, 27 Oct 2004, John Prevost wrote:
> The above works as long as you don't also want to give arguments to
> ocaml itself.
But that is precisely what I want. Please have a look at my postings.
--
regards, tf@cip.physik.uni-muenchen.de (o_
Thomas Fischbacher - http://www.cip.physik.uni-muenchen.de/~tf //\
(lambda (n) ((lambda (p q r) (p p q r)) (lambda (g x y) V_/_
(if (= x 0) y (g g (- x 1) (* x y)))) n 1)) (Debian GNU)
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Caml-list] Arg parsing
2004-10-28 12:44 ` Thomas Fischbacher
@ 2004-10-28 14:56 ` John Prevost
2004-11-04 14:42 ` Thomas Fischbacher
0 siblings, 1 reply; 12+ messages in thread
From: John Prevost @ 2004-10-28 14:56 UTC (permalink / raw)
To: Thomas Fischbacher; +Cc: caml-list
On Thu, 28 Oct 2004 14:44:27 +0200 (CEST), Thomas Fischbacher
<thomas.fischbacher@physik.uni-muenchen.de> wrote:
> On Wed, 27 Oct 2004, John Prevost wrote:
>
> > The above works as long as you don't also want to give arguments to
> > ocaml itself.
>
> But that is precisely what I want. Please have a look at my postings.
Well, could you be a bit more precise about what you need? The only
bit I see from your previous postings:
> tf@ouija:~$ perl -e 'print @ARGV' -- one tooth ree
is covered by what I have said, without needing --.
Exactly what options are you trying to give to ocaml, and what problem
are you seeing?
Perhaps if you gave us the specific command-line you're trying to run,
everything would be more clear.
John.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Caml-list] Arg parsing
2004-10-28 14:56 ` John Prevost
@ 2004-11-04 14:42 ` Thomas Fischbacher
2004-11-04 15:28 ` John Prevost
0 siblings, 1 reply; 12+ messages in thread
From: Thomas Fischbacher @ 2004-11-04 14:42 UTC (permalink / raw)
To: John Prevost; +Cc: caml-list
On Thu, 28 Oct 2004, John Prevost wrote:
> > But that is precisely what I want. Please have a look at my postings.
>
> Well, could you be a bit more precise about what you need? The only
> bit I see from your previous postings:
>
> > tf@ouija:~$ perl -e 'print @ARGV' -- one tooth ree
>
> is covered by what I have said, without needing --.
The point is, I have something.ml which I can compile to an application
that parses its own args. Now I want to be able to #use "something.ml"
from within ocaml in such a way that it operates on the extra application
args I passed to the ocaml interpreter without having to change any code.
--
regards, tf@cip.physik.uni-muenchen.de (o_
Thomas Fischbacher - http://www.cip.physik.uni-muenchen.de/~tf //\
(lambda (n) ((lambda (p q r) (p p q r)) (lambda (g x y) V_/_
(if (= x 0) y (g g (- x 1) (* x y)))) n 1)) (Debian GNU)
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Caml-list] Arg parsing
2004-11-04 14:42 ` Thomas Fischbacher
@ 2004-11-04 15:28 ` John Prevost
2004-11-04 20:40 ` Thomas Fischbacher
0 siblings, 1 reply; 12+ messages in thread
From: John Prevost @ 2004-11-04 15:28 UTC (permalink / raw)
To: Thomas Fischbacher; +Cc: caml-list
On Thu, 4 Nov 2004 15:42:47 +0100 (CET), Thomas Fischbacher
<thomas.fischbacher@physik.uni-muenchen.de> wrote:
> The point is, I have something.ml which I can compile to an application
> that parses its own args. Now I want to be able to #use "something.ml"
> from within ocaml in such a way that it operates on the extra application
> args I passed to the ocaml interpreter without having to change any code.
Perhaps if you explained why you want to do this, it would be easier
for us to help you. For example, if you're using #use to test out
argument parsing code, perhaps this could help you:
module Sys =
struct
include Sys
let argv = [| "testprogram"; "my"; "arguments"; "for"; "testing" |]
end
Other than that, I'm having a *really* hard time figuring out why you
would want to examine your command line arguments from an interactive
program.
John.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Caml-list] Arg parsing
2004-11-04 15:28 ` John Prevost
@ 2004-11-04 20:40 ` Thomas Fischbacher
0 siblings, 0 replies; 12+ messages in thread
From: Thomas Fischbacher @ 2004-11-04 20:40 UTC (permalink / raw)
To: John Prevost; +Cc: caml-list
On Thu, 4 Nov 2004, John Prevost wrote:
> Perhaps if you explained why you want to do this, it would be easier
> for us to help you. For example, if you're using #use to test out
> argument parsing code, perhaps this could help you:
>
> module Sys =
> struct
> include Sys
> let argv = [| "testprogram"; "my"; "arguments"; "for"; "testing" |]
> end
>
> Other than that, I'm having a *really* hard time figuring out why you
> would want to examine your command line arguments from an interactive
> program.
That's precisely what I want to do. And I do not see why I should have to
bend over backwards and write such extra code for a task as simple as that
which could be easily resolved by just making the ocaml interpreter accept
a '--' arg properly...
--
regards, tf@cip.physik.uni-muenchen.de (o_
Thomas Fischbacher - http://www.cip.physik.uni-muenchen.de/~tf //\
(lambda (n) ((lambda (p q r) (p p q r)) (lambda (g x y) V_/_
(if (= x 0) y (g g (- x 1) (* x y)))) n 1)) (Debian GNU)
^ permalink raw reply [flat|nested] 12+ messages in thread
* Problem with location.
2004-10-26 19:56 Arg parsing Thomas Fischbacher
2004-10-26 20:13 ` [Caml-list] " William Lovas
@ 2004-10-26 21:05 ` sejourne_kevin
2004-10-26 21:36 ` [Caml-list] " Tiago Dionizio
1 sibling, 1 reply; 12+ messages in thread
From: sejourne_kevin @ 2004-10-26 21:05 UTC (permalink / raw)
To: caml-list
Hi list.
On my linux(debian) ocamlrun is in /usr/bin. I remember that ocaml are
is this directory on all other linux I try. This is a probleme for
script mode :
http://caml.inria.fr/ocaml/htmlman/manual023.html
" #!/usr/local/bin/ocamlrun /usr/local/bin/ocaml "
because with this force me to use an unstandard way.
I can't make a program that use the script mode and
give it to people. The trick use in cduce for configuring isn't
nice(http://www.cduce.org) because it take two files...
How can I solve my problem ??
regards,
Kévin.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Caml-list] Problem with location.
2004-10-26 21:05 ` Problem with location sejourne_kevin
@ 2004-10-26 21:36 ` Tiago Dionizio
2004-10-26 22:33 ` Matt Gushee
0 siblings, 1 reply; 12+ messages in thread
From: Tiago Dionizio @ 2004-10-26 21:36 UTC (permalink / raw)
To: caml-list; +Cc: sejourne_kevin
You can try using:
#!/usr/bin/env ocamlrun
although i don't know how reliable this is, it should work.
Tiago
On Tue, 26 Oct 2004 23:05:23 +0200, sejourne_kevin
<sejourne_kevin@yahoo.fr> wrote:
> Hi list.
>
> On my linux(debian) ocamlrun is in /usr/bin. I remember that ocaml are
> is this directory on all other linux I try. This is a probleme for
> script mode :
> http://caml.inria.fr/ocaml/htmlman/manual023.html
> " #!/usr/local/bin/ocamlrun /usr/local/bin/ocaml "
>
> because with this force me to use an unstandard way.
> I can't make a program that use the script mode and
> give it to people. The trick use in cduce for configuring isn't
> nice(http://www.cduce.org) because it take two files...
> How can I solve my problem ??
>
> regards,
>
> Kévin.
>
> _______________________________________________
> 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] 12+ messages in thread
* Re: [Caml-list] Problem with location.
2004-10-26 21:36 ` [Caml-list] " Tiago Dionizio
@ 2004-10-26 22:33 ` Matt Gushee
0 siblings, 0 replies; 12+ messages in thread
From: Matt Gushee @ 2004-10-26 22:33 UTC (permalink / raw)
To: caml-list
On Tue, Oct 26, 2004 at 09:36:10PM +0000, Tiago Dionizio wrote:
> You can try using:
>
> #!/usr/bin/env ocamlrun
>
> although i don't know how reliable this is, it should work.
Not 100% portable, I believe, but it should work on any Linux system,
and probably also *BSD and Solaris. This technique is commonly used in
the Python world.
--
Matt Gushee When a nation follows the Way,
Haven Rock Press Horses bear manure through
Englewood, Colorado, USA its fields;
books@havenrock.com When a nation ignores the Way,
Horses bear soldiers through
its streets.
--Lao Tzu (Peter Merel, trans.)
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2004-11-04 20:40 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-10-26 19:56 Arg parsing 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
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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox