[mercury-users] Arguments to program

Fergus Henderson fjh at cs.mu.OZ.AU
Thu Feb 19 10:09:34 AEDT 2004


On 18-Feb-2004, Dieter Büttner <judisun at t-online.de> wrote:
> How do I pass arguments to a mercury program? I assumed it would be by the 
> shell command ./factorial 11 (for example).

That's correct. 

The arguments can then be retrieved using the standard library routine
`command_line_arguments' in the module `io'.

For example:

	:- module factorial.
	:- interface.
	:- import_module io.

	:- pred main(io__state::di, io__state::uo) is det.

	:- implementation.
	:- import_module string.

	main(X) -->
		command_line_arguments(Args),
		( { Args = [Num], string__to_int(Num, X) } ->
			{ Y = fac(X) },
			print("Y = "), print(Y), nl
		;
			print("invalid argument(s)")
		).

	:- func fac(int) = int.
	...

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
The University of Melbourne         |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-users mailing list
post:  mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-users-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the users mailing list