# Want to get minimal term\_expansion example working

**URL:** <https://swi-prolog.discourse.group/t/want-to-get-minimal-term-expansion-example-working/8739>\
**Category:** Help!\
**Tags:** macro\
**Created:** [January 21, 2025, 3:29am UTC](https://swi-prolog.discourse.group/t/want-to-get-minimal-term-expansion-example-working/8739 "2025-01-21T03:29:46Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![kuniaki.mukai](https://avatars.discourse-cdn.com/v4/letter/k/c67d28/32.png) [@kuniaki.mukai](https://swi-prolog.discourse.group/u/kuniaki.mukai)\
**Post date:** [January 21, 2025, 1:53pm UTC](https://swi-prolog.discourse.group/t/want-to-get-minimal-term-expansion-example-working/8739/2 "2025-01-21T13:53:51Z")

</div>

> [@robert314](#):
>
> I want to: write a prolog file that when consulted then it rewrites the term `xaxis` in the file consulting it or user’s session to the compound term `vector(1, 0, 0)`.
> 
> But what I’m getting is: `xaxis`, no rewriting happening

If I understood correctly your question, one of the best answers should be the following.

> [@Term\_expansion not applied](https://swi-prolog.discourse.group/t/term-expansion-not-applied/2731/2):
>
> [term\_expansion/2](https://www.swi-prolog.org/pldoc/doc_for?object=term_expansion/2) is only called on the toplevel term. If you want to perform transformations inside the term you need to do so yourself. An intermediate step is provided by [goal\_expansion/2](https://www.swi-prolog.org/pldoc/doc_for?object=goal_expansion/2), which is called for each goal term in a clause.
> 
> Also note that [term\_expansion/2](https://www.swi-prolog.org/pldoc/doc_for?object=term_expansion/2) is called only once per term, i.e., only the first answer of the expansion is used. [goal\_expansion/2](https://www.swi-prolog.org/pldoc/doc_for?object=goal_expansion/2) is called on the goal until _fixed point_ is reached.

---

_[View the full topic](https://swi-prolog.discourse.group/t/want-to-get-minimal-term-expansion-example-working/8739)._
