What would be interesting, would be to replace depth-first search while remaining in the world of predicates and Horn clauses.
I say naïvely because on one hand you might not need all versions of the function, but on the other one you can also provide partial values, so it’s not either input or output.
For that you want tabled Prolog, or in other words Prolog executed by SLG-Resolution. The paradigmatic implementation is XSB Prolog:
SWI-Prolog also supports tabling but I think the XSB implementation is more mature.