[mercury-users] Perl shift || $defalt
Ralph Becket
rbeck at microsoft.com
Thu Apr 26 23:22:00 AEST 2001
> In Perl, it is very easy to say the following:
>
> the value of x is equal to the first data item in ARGV,
> or if ARGV is not defined then use the value 12:
>
> $x = shift || 12;
> print "$x\n";
>
> Thus, a program can either take values on STDIN or use hardcoded
> defaults with relative ease.
>
> Could someone show how to do this same thing in Mercury?
main -->
io__command_line_args(ArgV),
{ if ArgV = [Arg1 | _] then X = Arg1 else X = "12" },
io__format("%s\n", [s(X)]).
It's not quite the same since `shift' returns the first argument and
then removes it from argv; in Mercury you have to handle the list
explicitly.
-- Ralph
--------------------------------------------------------------------------
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