2

I am writing a module A which defines term_expansion/2. As a side-effect, when it becomes imported by module B, the terms defined in module B will be expanded as described in module A. However, I did not manage to also expand the terms which come from shell, after a user has loaded B using ?- [B]. in an interactive session. How do I manipulate the queries/directives which come from shell and call them instead?

Example:

If the user types

?- my_append("AB", "CD", L).

I want to expand the my_append-term to something like this (but not restricted to it) which is then called after expansion:

?- extra_args(A0, A1), my_append_with_extra_args(A0, A1, "AB", "CD", L).

To be clear: The term-expansion/-manipulation itself is not the problem – what I need to know is the hook which can I use/redefine like term_expansion/2.

Community
  • 1
  • 1
user3389669
  • 799
  • 6
  • 20

1 Answers1

2

The predicate I was looking for is expand_query/4.

user3389669
  • 799
  • 6
  • 20
  • 2
    Does a simple `goal_expansion/2` rule not suffice? This way, you could use the goal also within your programs, not only from the query. – mat Sep 19 '16 at 08:52
  • 1
    @mat `goal_expansion/2` triggers too often. Performing a simple `?- append("a","b",L).` triggers it four times, instead of one time. Also, it is triggered during the `term_expansion/2`-process – and that is not what I am looking for. – user3389669 Sep 19 '16 at 09:44
  • 1
    @mat Surprisingly, I still haven't found a way to [expand Prolog queries](https://stackoverflow.com/questions/46614561/implementing-partial-evaluation-in-swi-prolog) using `goal_expansion/2`. Is this possible somehow? – Anderson Green Oct 08 '17 at 01:37