Find occurrence of predicate anywhere it exists in a nested, compound object?

Does this do what you want?

use_module(library(apply)).

find_in_term(Functor, Within, FoundArgs) :-
    Within =.. [Functor|FoundArgs].
find_in_term(Functor, Within, FoundArgs) :-
    Within =.. [_|WithinArgs],
    convlist(find_in_term(Functor), WithinArgs, FoundArgsList),
    member(FoundArgs, FoundArgsList).
3 Likes