The difference between using argv
and args
is evident when
Prolog is invoked with numbers as arguments.
The objects returned by unix(argv(_))
are Prolog objects; that
is, if the command line argument is a number, then it will be returned
as a number. Thus:
% prolog 1 . . . | ?- unix(argv([1])). yes | ?- unix(argv(['1'])). no | ?- unix(args(['1'])). yes
% prolog 1 6.999999 . . . | ?- unix(argv(X)). X = [1, 6.9999999E+00] | ?- unix(args(X)). X = ['1', '6.999999']
So if your program treats the command line argument as a number, use
the form with argv
, but if it is to be treated as a string, use
args
. For example if the program is called with a number and
performs some arithmetic operation on the argument then displays the
result, use argv
.
| ?- [user]. | runtime_entry(start) :- unix(argv([A])), Y is A+1, display(Y). | ^D % user compiled in module user, 0.083 sec 8 bytes yes | ?- runtime_entry(start). 46 yes