SWI-Prolog / packages-pengines

Pengines: Prolog engines
11 stars 13 forks source link

pengines_io goal expansion example is not working #36

Open triska opened 6 years ago

triska commented 6 years ago

I try to construct a small working example from the documentation of pengines_io.

So I create ma.pl with the following content:

:- module(ma, []).

:- use_module(library(pengines)).


:- pengine_application(myapp).
:- use_module(myapp:library(pengines_io)).
myapp:goal_expansion(In,Out) :-
        pengine_io_goal_expansion(In, Out).


pred :-
        format("hello!\n", []).

The bold part is directly copied from the library documentation.

Now, I get:

?- listing(pred).
ma:pred :-
    format("hello!\n", []).

However, when I change the bold part to (change in bold: myappma):

:- pengine_application(myapp).
:- use_module(myapp:library(pengines_io)).
ma:goal_expansion(In,Out) :-
        pengine_io_goal_expansion(In, Out).

then I get the expected expansion:

?- listing(pred).
ma:pred :-
    pengine_format("hello!\n", []).

Please check the example in the documentation, and whether it is working as intended. Thank you!

JanWielemaker commented 6 years ago

This is to be expected. ma is does not inherit from the Pengine application module. The intended scenario is that the pengine application module defines the Pengine application settings and default environment. If you create a Pengine the library creates a temporary module that inherits from the application. This makes the predicates from the application visible as fall-back (you can overrule them). This also holds for goal/term expansion and operators.

Not sure how to fix that in the docs. Apparently It is not clear. If you think you now understand what is going on and you see a better formulation, please submit a pull request on the docs.