Factors of an integer: Difference between revisions

→‎{{header|Mercury}}: It's good to have the declaration match the definition. It's also good not to reference predicates no longer in existence.
m (→‎fac.m: Forgot to change to a more meaningful name.)
(→‎{{header|Mercury}}: It's good to have the declaration match the definition. It's also good not to reference predicates no longer in existence.)
Line 1,321:
 
=={{header|Mercury}}==
Mercury is both a logic language and a functional language. As such there are two possible interfaces for calculating the factors of an integer. This code shows both styles. Note that much of the code here is ceremony put in place to have this be something which can actually compile. The actual factoring is contained in the predicate <code>factor/2</code> and in the function <code>factor/1</code>. The predicate <code>main/2</code> is just the entry point for the program and the predicate <code>main2/3</code> is used to do command line processing so multiple numbers can be factored.
 
The function form is implemented in terms of the predicate form rather than duplicating all of the predicate code.
Line 1,364:
factor(N) = L :- factor(N, L).
 
:- pred print_argprint_factors(string::in, io::di, io::uo) is det.
print_factors(Arg, !IO) :-
(string.to_int(Arg, N) ->