There have been some improvements to term_expansion/2, see How to get to a fixed point with goal expansion?
For this particular situation, wrap_predicate/4 turned out to be the easiest (and best?) solution.
There have been some improvements to term_expansion/2, see How to get to a fixed point with goal expansion?
For this particular situation, wrap_predicate/4 turned out to be the easiest (and best?) solution.