Term_expansion/2 vs goal_expansion/2

I have read the relevant documentation, but I still don’t understand the difference between these two predicates. Could anybody explain or point me to a source?
Cheers/JC

term_expansion/2 is the original … it takes an entire fact or clause and expands it.

goal_expansion/2 came later, to handle a common case when you want to expand individual goals (in the body of a clause) without having to deal with all control stuff ((,)/2, (;)/2, (->)/2, (+)/1, etc.).

4 Likes

This is related information to goal_expansion/2.

Once I tried to use goal_expansion/2 to expand query goals which contain private macros, but it didn’t work. After asking, I was replied in SWI-Prolog mailing list from Jan W. several years ago, there was some limitation of goal_expansion/2 at least for my purpose. Unfortunately I forgot detail. Anyway in stead of goal_expansion/2, I had to use expand_goal/4 and term_expansion/2 to expand queries contains the private macros. Although the codes still works well, it would be good for us if goal_expansion/2 works also for query.

Kuniaki Mukai

1 Like

There have been some improvements to term_expansion/2, see How to get to a fixed point with goal expansion?

For this particular situation, wrap_predicate/4 turned out to be the easiest (and best?) solution.

1 Like

It is good to hear on some improvements on term_expansion/2, on which my pack pac (closure) library is heavily based. But I vaguely remember that my trouble was not related to such elegant “fixpoint” problem but merely to that my goal_expansion/2 clauses were not activated. It was strange for me but also it seemed it was beyond my efforts. I will go back the trouble when I have time in the future.

Thaks for reply.

Kuniaki Mukai

Thank you for all the useful suggestions!