# Copy\_term/2 is not relational and this is a problem

**URL:** <https://swi-prolog.discourse.group/t/copy-term-2-is-not-relational-and-this-is-a-problem/9079>\
**Category:** Predicate\
**Tags:** bug\
**Created:** [June 27, 2025, 7:25pm UTC](https://swi-prolog.discourse.group/t/copy-term-2-is-not-relational-and-this-is-a-problem/9079 "2025-06-27T19:25:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![gabe-rbo](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/gabe-rbo/32/7241_2.png) [@gabe-rbo](https://swi-prolog.discourse.group/u/gabe-rbo)\
**Post date:** [June 27, 2025, 7:25pm UTC](https://swi-prolog.discourse.group/t/copy-term-2-is-not-relational-and-this-is-a-problem/9079/1 "2025-06-27T19:25:55Z")

</div>

I’m currently trying to create an EBG using SWI-Prolog, however, copy\_term/2 is not working properly as it should in the ISO Standard.

When i try to copy something like:

copy\_term( (n\_queens( GenQueens, GenSolution ), GenBody ), ( n\_queens( [1, 2, 3, 4], Solution ), ( perm( [1, 2, 3, 4], P ), safe( P ))).

It succeeds but GenBody is not a copy of ( perm( [1, 2, 3, 4], P ), safe( P ) ) because GenBody is a variable and copy-term/2 is not relational.

How can i work around this?

---

<div class="post-metadata">

**Author:** ![gabe-rbo](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/gabe-rbo/32/7241_2.png) [@gabe-rbo](https://swi-prolog.discourse.group/u/gabe-rbo)\
**Post date:** [June 27, 2025, 9:12pm UTC](https://swi-prolog.discourse.group/t/copy-term-2-is-not-relational-and-this-is-a-problem/9079/3 "2025-06-27T21:12:18Z")

</div>

This is not a solution, because in EBG, GenBody’s perm list neither GenQueens should be instantiated. copy\_term/2 should be relational. In EBG we always want to do copy\_term((GenGoal :- GenBody), (Goal :- Body)), not the other way around.

---

<div class="post-metadata">

**Author:** ![gabe-rbo](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/gabe-rbo/32/7241_2.png) [@gabe-rbo](https://swi-prolog.discourse.group/u/gabe-rbo)\
**Post date:** [June 27, 2025, 9:34pm UTC](https://swi-prolog.discourse.group/t/copy-term-2-is-not-relational-and-this-is-a-problem/9079/6 "2025-06-27T21:34:50Z")

</div>

You’re right, however, in the ISO Standard, copy\_term/2 is relational, and in GNU Prolog it also is:

> **[Term processing](http://www.gprolog.org/manual/html_node/gprolog028.html#sec85)**

This important because we want it to copy both ways. SWI-Prolog implementation is most-likely wrong.

---

<div class="post-metadata">

**Author:** ![gabe-rbo](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/gabe-rbo/32/7241_2.png) [@gabe-rbo](https://swi-prolog.discourse.group/u/gabe-rbo)\
**Post date:** [June 27, 2025, 9:51pm UTC](https://swi-prolog.discourse.group/t/copy-term-2-is-not-relational-and-this-is-a-problem/9079/9 "2025-06-27T21:51:10Z")

</div>

I’m truly very sorry, i was using clause(Goal, Body) instead of clause(GenGoal, GenBody) 🤦‍♂️ Sorry for wasting your time! Your implementation is correct 🙇‍♂️
