In nested if-then-else, it is common to omit redundant parentheses, yielding:
min(List1, List2, Output) :-
length(List1, N),
length(List2, M),
( N < M -> Output = true
; N =:= M -> Output = equal
; Output = other
).
In Prolog, it is good practice to use pattern matching when possible, because this yields more general, more declarative and more readable programs than using if-then-else. For this particular case of conditions, check out the compare/3
library predicate. compare/3
lets you reify the relation of the two lengths into an atom, and you can use that atom to describe the three conditions with pattern matching:
lists_output(List1, List2, Output) :-
length(List1, L1),
length(List2, L2),
compare(Order, L1, L2),
order_output(Order, Output).
order_output(<, true).
order_output(=, equal).
order_output(>, other).
Sample queries and results:
?- lists_output([_,_], [_,_,_], Output).
Output = true.
?- lists_output([_,_,_], [_,_,_], Output).
Output = equal.
?- lists_output([_,_,_,_], [_,_,_], Output).
Output = other.