Logtalk hangs out when loading certain modules like `library(dif)`
I don't have a clue where the problem is (Scryer or Logtalk), but there seems to be an infinite loop when we try to load certain modules in Logtalk files. This doesn't happen when loaded directly in Prolog code.
Take this minimum case:
:- initialization((
logtalk_load(app),
app::run
)).
:- use_module(library(dif)).
:- object(app).
run :- write("Hello World!").
:- end_object.
The module that causes the problem is dif, because if you remove it, it loads and works as expected. But I don't see anything in dif that could make Logtalk go so bad (attribute variables?)
cc @pmoura
I can reproduce the hang just by doing:
$ scryerlgt
...
?- use_module(library(dif)).
Actually, the issue is with:
?- use_module(library(atts)).
Commenting out the definition of the predicate user:term_expansion/2 in that file solves the hanging... but still looking to understand why.
Found the cause of the hang. Logtalk defines a user pseudo-object that represents the plain Prolog database and declares user:term_expansion/2 as a multifile and dynamic predicate as common in most Prolog system supporting it. Somehow this clashes with the definition of the predicate inside the atts module. Possibly, an issue in Scryer implementation of term-expansion assuming that the predicate is here also expected to be multifile and dynamic. @mthom ? If so, the atts module is missing the directives:
:- multifile(user:term_expansion/2).
:- dynamic(user:term_expansion/2).
:- multifile(user:goal_expansion/2).
:- dynamic(user:goal_expansion/2).
But adding them doesn't solve the loading hang. A quick workaround until we sort this out is for you to edit the logtalk3/core/user.lgt file and comment out the directives there. Or, in alternative, use:
:- if(\+ current_logtalk_flag(prolog_dialect, scryer)).
:- multifile(user::term_expansion/2).
:- dynamic(user::term_expansion/2).
:- multifile(user::goal_expansion/2).
:- dynamic(user::goal_expansion/2).
:- endif.
Searching the files src/lib shows the user:term_expansion/2 predicate being defined in the atts, dcgs, and table_wrapper modules. Thus, the predicate is implicitly multifile. But I cannot find in the sources any multifile/1 directive for it.
Re-testing with 40d3345cd538b826bc91f3592562c4a32f69415e:
$ scryerlgt
...
?- use_module(library(dif)).
true.