Is there any predicate for making a copy of a compound term and un-unifying any unified variables, so that the resulting term has only singletons? In other words, is there something like a copy_to_singletons/2 that would let me do this:
?- copy_to_singletons(foo(A, A), X).
X = foo(_1, _2).
I’ve been using this as a workaround, but it seems needlessly complex:
copy_to_singletons(Term, TermOut) :-
copy_term(Term, Term1, _),
numbervars(Term1),
mapsubterms([T0,_]>>var_number(T0, _), Term1, TermOut),
I end up having to make two copies because for whatever reason, mapsubterms/3 doesn’t call the goal for variables. Not sure what the reasoning is behind that, but it does mean I have to copy and ground before calling it.
Is there a better way?