[mercury-users] Arguments to program
Peter Ross
pro at missioncriticalit.com
Thu Feb 19 19:09:57 AEDT 2004
On Thu, Feb 19, 2004 at 10:09:34AM +1100, Fergus Henderson wrote:
> 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) -->
That should be main -->
> 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.
> ...
--------------------------------------------------------------------------
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