question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

consult doesn't call initialization/1 directive goals

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:32 (21 by maintainers)

github_iconTop GitHub Comments

1reaction
jariazavalverdecommented, May 26, 2020

Great! Please feel free to add the header that you consider appropriate. You can distribute it under the same Logtalk license.

1reaction
jariazavalverdecommented, May 26, 2020

This (d84181b) is the last major change in the Tau Prolog interface. Thread.prototype.query becomes asynchronous due to goal expansion. @pmoura Hopefully this is the last change for your script: 😄

var readlineSync = require("readline-sync");
var pl = require("./node_modules/tau-prolog/modules/core.js");
require("./node_modules/tau-prolog/modules/format.js")(pl);
require("./node_modules/tau-prolog/modules/js.js")(pl);
require("./node_modules/tau-prolog/modules/lists.js")(pl);
require("./node_modules/tau-prolog/modules/os.js")(pl);
require("./node_modules/tau-prolog/modules/random.js")(pl);
require("./node_modules/tau-prolog/modules/statistics.js")(pl);

var max_answers = process.argv[2] || 100;
var session = pl.create(50000);
var compose = (f,g) => x => f(g(x));
var show = x => console.log(pl.format_answer(x, session));
var repl = function() {
    var query = readlineSync.question("?- ", {keepWhitespace: true}) + "\n";
    session.query(query, {success: function(_goal) {
        session.answers(function(answer) {
            show(answer);
            if(answer === false || pl.type.is_error(answer))
                repl();
        }, max_answers);
    }, error: compose(repl, show)});
};
session.consult("../logtalk3/adapters/unsupported/tau.pl", {success: function() {
    session.consult("../logtalk3/paths/paths.pl", {success: function() {
        session.consult("../logtalk3/core/core.pl", {success: function() {
            repl();
        }, error: show});
    }, error: show});
}, error: show});
Read more comments on GitHub >

github_iconTop Results From Across the Web

Calling predicate at the begining of the run - Stack Overflow
A special directive is initialization/1: Call Goal after loading the source file in which this directive appears has been completed.
Read more >
(initialization)/1 - SWI-Prolog
This means that arbitrary goals can only be called from a directive by means of the initialization/1 directive. SWI-Prolog does not enforce this...
Read more >
multiple files in GNU Prolog? - Google Groups
My understanding is that I am not using Prolog modules, and that SWI Prolog's multifile directive permits non-contiguous use of predicates,. :- multifile([ ......
Read more >
Simple term_expansion debugging - Nice to know - SWI-Prolog
When a term passes through term_expansion/2 trying to debug/understand the term expansion can be challenging at first. One effective aid in ...
Read more >
Top 18 Most Common AngularJS Developer Mistakes - Toptal
debugInfoEnabled is set to false, calling .scope() on a DOM node will return undefined . That is one of the few recommended options...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found