`copy_term/2`

meta-logical`copy_term(`

`+Term, -Copy``)`

Makes a copy of `+Term`
in which all variables have been replaced by new variables
that occur nowhere outside the newly created term.

`Term`term-
`Copy`term

- This is precisely the effect that would have been obtained from the
definition below, although the system implementation of
`copy_term/2`

is more efficient.copy_term(Term, Copy) :- recorda(copy, copy(Term), DBref), instance(DBref, copy(Temp)), erase(DBref), Copy = Temp.

- When you call
`clause/[2,3]`

or`instance/2`

, you get a new copy of the term stored in the database, in precisely the same sense that`copy_term/2`

gives you a new copy. - Used in writing interpreters for logic-based languages.

- A naive way to attempt to find out whether one term is a copy of another:
identical_but_for_variables(X, Y) :- \+ \+ ( numbervars(X, 0, N), numbervars(Y, 0, N), X = Y ).

This solution is sometimes sufficient, but will not work if the two terms have any variables in common.

- If you want the test to succeed even when the two terms do have
some variables in common, you need to copy one of them; for example,
identical_but_for_variables(X, Y) :- \+ \+ ( copy_term(X, Z), numbervars(Z, 0, N), numbervars(Y, 0, N), Z = Y ).

`atomic/1`

, `float/1`

, `integer/1`

,
`nonvar/1`

, `number/1`

, `var/1`

, `simple/1`

,
`compound/1`

, `callable/1`

, `ground/1`

, `simple/1`

,
`db_reference/1`

.