All the predicates in library(occurs) have the same argument pattern:
{prefix}_{term|var}(SubTerm, Term[, Extra])
where Extra includes any other arguments. Why does the SubTerm
argument appear first? The answer involves library(call) and
library(maplist). Here are some of the things you can do with the
arguments this way around:
terms_containing_term(SubTerm, Terms, Selected) :-
include(contains_term(SubTerm), Terms, Selected).
% if member(Term, Terms), then Term will be included in
% Selected iff contains_term(SubTerm, Term) succeeds.
terms_free_of_var(SubTerm, Terms, Selected) :-
exclude(contains_var(SubTerm), Terms, Selected).
% if member(Term, Terms), then Term will be included in
% Selected iff contains_var(SubTerm, Term) fails.
tallies_of_term(SubTerm, Terms, Tallies) :-
maplist(occurrences_of_term(SubTerm), Terms, Tallies).
% if nth1(N, Terms, Term), then nth1(N, Tally, Tallies)
% where occurrences_of_term(SubTerm, Term, Tally).
The same argument order is used for sub_term/2 even though
it is not used in this way, in order to preserve consistency.