Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot reexport module from package? #97

Open
aherranz opened this issue Sep 24, 2024 · 3 comments
Open

Cannot reexport module from package? #97

aherranz opened this issue Sep 24, 2024 · 3 comments

Comments

@aherranz
Copy link

I am loading the rfuzzy package and I get an error message "reexport/1 directive not allowed in shell"

Ciao 1.23.0 [LINUXx86_64]
?- use_package(rfuzzy).
{Using package /home/angel/.ciao/RFuzzy/lib/rfuzzy/rfuzzy.pl
{Using package /home/angel/.ciaoroot/v1.23.0-m1/core/lib/hiord/hiord.pl
Note: module hiord_rt already in executable, just made visible
}
ERROR: (lns 5-6) reexport/1 directive not allowed in shell
Note: module aggregates already in executable, just made visible
Note: module terms already in executable, just made visible
Note: module basic_props already in executable, just made visible
{Including /home/angel/.ciao/RFuzzy/lib/rfuzzy/rfuzzy_ops.pl
}


INFO: Rfuzzy (Ciao Prolog package to compile Rfuzzy programs into a pure Prolog programs):  compiling ...    

}

yes
?- 

The main module of the library is this one:

:- package(rfuzzy).

:- use_package(hiord).

:- use_module(library(rfuzzy/rfuzzy_rt)). 
:- reexport(library(rfuzzy/rfuzzy_rt)).

:- use_module(library(aggregates), [findall/3]).
:- use_module(library(terms),[copy_args/3]).
:- use_module(engine(basic_props), [list/1]).
:- include(library(rfuzzy/rfuzzy_ops)).

:- load_compilation_module(library(rfuzzy/rfuzzy_tr)).
:- add_sentence_trans(rfuzzy_tr:rfuzzy_trans_sentence/3, 730).

I don't know the implication of the error, I am not sure if predicates are reexported or not. Can I avoid such a message? (I can update the rfuzzy library).

Regards.

@jfmc
Copy link
Member

jfmc commented Sep 24, 2024

Hi @aherranz. Some declarations, like reexport, do not make sense from the toplevel/REPL/shell. To avoid that it is possible to deactivate that code using conditional compilation as follows:

:- if(defined('SHELL')).
% put here what is required in a toplevel (it can be empty)
:- else.
% and here what cannot run in a toplevel
:- endif.

for example:

:- if(defined('SHELL')).
:- else.
:- reexport(library(rfuzzy/rfuzzy_rt)).
:- endif.

Another issue is whether reexport for a package is really required (usually we never need it but I'm not familiar with rfuzzy).

Let us know if you need to modify the goal expansion when run in a toplevel context. This is also possible but not really well documented.

@aherranz
Copy link
Author

But reexport is not being used from the REPL, in the interpreter I am just doing use_package(rfuzzy). The reexport is in the main module of the library.

I am not familiar with the implementation of rfuzzy, I am just trying to use it. Thanks for your orientation.

@jfmc
Copy link
Member

jfmc commented Sep 24, 2024

Actually doing a use_package from the toplevel inserts the package contents, like an include. Thus adding the conditional compilation to the rfuzzy package source will fix that problem.

Edit: More details on this. Packages in Ciao are not really modules, but source files that are directly included in the context the use them. Most of the time, the source is a collection of directives like use_module, other use_package, some operator definitions, and other directives to enable user-defined code expansions (like add_sentence_trans). This modified rfuzzy.pl package may fix the issues with reexport in a toplevel:

:- package(rfuzzy).

:- use_package(hiord).

:- use_module(library(rfuzzy/rfuzzy_rt)). 
:- if(defined('SHELL')).
:- else.
:- reexport(library(rfuzzy/rfuzzy_rt)).
:- endif.

:- use_module(library(aggregates), [findall/3]).
:- use_module(library(terms),[copy_args/3]).
:- use_module(engine(basic_props), [list/1]).
:- include(library(rfuzzy/rfuzzy_ops)).

:- load_compilation_module(library(rfuzzy/rfuzzy_tr)).
:- add_sentence_trans(rfuzzy_tr:rfuzzy_trans_sentence/3, 730).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants