While working on a directive to allow iterating through succeeding depths of recursion for an arbitrary predicate (even if the predicate does not terminate in normal prolog), it was pointed out that I should use
functor/3 instead of
copy_term/2 to obtain a most generic term.
What is the difference between these two if the argument of the compound terms is not instantiated?
34 ?- copy_term(myterm(T),NewTerm1). NewTerm1 = myterm(_1194). 35 ?- functor(NewTerm2,myterm,1). NewTerm2 = myterm(_1104).
In my code it turns out the term generated by
functor/3 is more generic, than the one produced by
copy_term/2 as Jan pointed out.
I can’t grasp why the difference, if T is not instantiated.
EDIT: I understand
copy_term/2 shares ground terms and
functor/3 does not (of course), but here we’re dealing with an argument which is not instantiated.