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:
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.
Unfortunately, varnumbers/3 is going to (by design) have the same problem as copy_term, which is to say that common variables in the original will become common variables in the copy. As for what I’m trying to do, I want to reason about the structure of Prolog clauses themselves, so a non-singleton variable is significant but that does not mean the two (or more) instances will be identical.
I don’t understand that. I’ve seen a lot of things during my Prolog years, but never the desire to stop sharing two variables. As they are clause structures, they are not cyclic and thus a simple transformation as mapsubterms/3 does the job. You can’t use that as it doesn’t call the mapper for variables (it is still unclear whether that is a good decision. There are arguments both ways).
Well, it’s always nice to be unique I want to map them into term_positions. I don’t want to use them semantically, I want to use them syntactically, and they are two different tokens in the stream.