Command-line arguments: Difference between revisions

m
→‎Using the Arg module: update link/formatting
m (Improve shell code for calling a lang program)
m (→‎Using the Arg module: update link/formatting)
Line 1,810:
done</syntaxhighlight>
 
=== Using the [httphttps://camlocaml.inria.fr/pub/docs/manual-ocamlorg/librefapi/Arg.html Arg] module ===
 
<syntaxhighlight lang="ocaml">(* default values *)
let somebool = ref false
Line 1,831 ⟶ 1,830:
(fun x -> raise (Arg.Bad ("Bad argument : " ^ x)))
usage;
Printf.printf " %b %d '%s'\n" !somebool !someint !somestr;</syntaxhighlight>
<pre>
%$ ocaml arg.ml --help
usage: tmparg.ml [-b] [-s string] [-d int]
-b : set somebool to true
-s : what follows -s sets some string
-d : some int parameter
--help Display this list of options
--help Display this list of options
 
%$ ocaml arg.ml -d 4 -b -s blabla
Printf.printf " %b %d '%s'\n" !somebool !someint !somestr;
true 4 'blabla'
;;</syntaxhighlight>
 
 
%$ ocaml arg.ml --help
false 0 ''
usage: tmp.ml [-b] [-s string] [-d int]
</pre>
-b : set somebool to true
-s : what follows -s sets some string
-d : some int parameter
--help Display this list of options
% ocaml arg.ml -d 4 -b -s blabla
true 4 'blabla'
% ocaml arg.ml
false 0 <nowiki>''</nowiki>
 
=={{header|Odin}}==
559

edits