4

Question - Asserted dynamic predicates don't save permanently, after creating new session they're missing. How to save them permanently?

I'm using
Tau Prolog: A Prolog interpreter in JavaScript.

I'm loading prolog code from in html file because I haven't succeded to load it from external pl file.

In .js file I'm using following code:

session = pl.create();
if(session){
session.consult( "baza.pl" );

    //var query ="consult('baza.pl').";
    //session.query( query );
    //also consults this way
}

Then I later query that same session and insert new dynamic predicates with assertz. Everything is okay until I reload page (when new session makes there are only original predicates but no new ones).

I tried also

session.consult( "baza.pl" );
// consulting prolog code from external file but never succeeded.
var query ="load_dyn('baza.pl')"; 
//loads from internal script tag but not from external file 
var query =":- use_module('baza.pl')."; 
// I think this didn't succeed anyway
false
  • 10,264
  • 13
  • 101
  • 209
intersect
  • 74
  • 8
  • 1
    I don't see a built-in for this, (or even ISO predicates like portray_clause), presumably because you cannot directly access a console or the filesystem from Javascript. [See the list of built-ins](http://tau-prolog.org/documentation#prolog). Their sandbox page is able to save because it takes the source code text and submits it to a backend service. Presumably you could use [client-side storage](https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Client-side_web_APIs/Client-side_storage) from Tau, if you could find a way to render things to text. Maybe the author could explain more. – Daniel Lyons Feb 05 '19 at 20:31

1 Answers1

3

Tau Prolog has no method to save a session. You should save all the facts manually and consult them every time the page is loaded.

The toString method from the Session prototype generates a textual representation of the Prolog program with all the clauses and modules that have been loaded into the session. You can send this text to your server and write it into a file.

To load the program from an external file, you could send an asynchronous request to your server to get the content of it. Then, you can load the program with the consult method.