Attributed variables are treated like normal variables, except that their attributes are copied as specified by the corresponding copy_term handler. This would usually imply that properties of the variable which can be interpreted as unary constraints (such as its domain) are copied, while attributes that link the variable to other variables or objects are ignored.
If the term to be copied contains ground subterms (subterms without variables), then these subterms are shared between the original and the copy. This optimization is only visible when using the nonlogical setarg/3 primitive on such a subterm - the safest way to enforce copying in such circumstances is to add a dummy variable argument.
Note that when the structure of the term to be copied is known, then it is more efficient to use specialised unification code or a combination of functor/3 and arg/3 to do the job.
Success: copy_term(a, C). (gives C=a). copy_term(s(X,a,Y,X), C). (gives C=s(_1, a, _2, _1)). copy_term([X,2|Y], C). (gives C=[_1, 2| _2]). copy_term(X, C). copy_term(X, s(1,2,3)). X::5..8, copy_term(f(X), C). (gives C=f(_1{5..8})). Fail: copy_term(s(X,X), s(3,4)).