tau-prolog: consult doesn't call initialization/1 directive goals
the consult JavaScript function doesn’t call initialization/1 directive goals. For example, with:
session.consult( ":- initialization(write(hello))." );
session.query( "true." );
session.answers( x => console.log( pl.format_answer(x) ) );
we get:
$ node ./tp.js
true ;
false.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 1
- Comments: 32 (21 by maintainers)
Commits related to this issue
- fixed session reference in initialization/1 execution (Fix #142) — committed to tau-prolog/tau-prolog by jariazavalverde 4 years ago
- improved consult process to make it asynchronous (#142) — committed to tau-prolog/tau-prolog by jariazavalverde 4 years ago
- fixed op/3 directive (#142) — committed to tau-prolog/tau-prolog by jariazavalverde 4 years ago
Great! Please feel free to add the header that you consider appropriate. You can distribute it under the same Logtalk license.
This (d84181b) is the last major change in the Tau Prolog interface.
Thread.prototype.querybecomes asynchronous due to goal expansion. @pmoura Hopefully this is the last change for your script: 😄Thanks for debugging the issue. I would never guessed a Tau bug in the
op/3directive! I will update and resume testing.Sorry, it was a bug with the
op/3directive. I just tried logtalk and now it works correctly.Ok, let me do some experiments with your latest changes.
consult/1is asynchronous in the sense that the Tau Prolgo thread “falls asleep” until the file has finished loading, and then resolution continues. A file is not loaded until the previous one is loaded.The
consult/1built-in predicate should not be affected, since it was already asynchronous as it was incorporated into the Tau Prolog resolution logic. Maybe you could load your files more comfortably with Tau Prolog:This is an important change in the consult process, since from now on the
consultmethod is also an asynchronous process.consultacceptssuccessoption to be executed when the parsing is end, anderroroption to report an error:The
querymethod will also require this change due to the goal expansion.But that’s not standard behavior and it breaks existing code. They must be called after the file is parsed. The solution seems to be collecting all initialization goals from
session.consult()calls and then call the goals (in the order the directives were found; this is also key) after the file is fully parsed.But there’s another bug:
initialization/1directives must be called only after a file is finished loading. In the current implementation, the initialization goals seem to being called as soon as the directives are parsed. The solution could be calling the initialization goals right before the query (i.e. when processing thesession.query()call).Fixed!