0
votes

There, I've been trying this issue for over 2 days now and have got nothing to show for it. Therefore, would appreciate some help on this issue.

Issue: Attempting to assert a new predicate using Tau Prolog for Javascript returns a false result. The exact same query results in True when using SWI-Prolog.

The program is taken from a textarea in a HTML page. Everything is local on a single computer only.

**Prolog rules**
<textarea class="example-textinput example-program" id="program">
breads([parmesan, honeywheat]).
</textarea>

**Javascript in the same HTML page**
<script>
var session = pl.create();
var program = document.getElementById("program").value;
session.consult(program);
session.query(`asserta(chosen_meats(variable_to_be_asserted)).`);
session.answers(show())
function show() {
    // Return callback function
    return function (answer) {
        // Valid answer
        console.log(answer);
        if (pl.type.is_substitution(answer)) {
            // Get the value of the food
            var output = answer.lookup("X");
            console.log(output);
        }
    };
}
</script>

What I've attempted: Declaring dynamic predicates in Prolog. E.g

<textarea class="example-textinput example-program" id="program">
    breads([parmesan, honeywheat]).
    :- dynamic chosen_meats/1.
</textarea>

Changing to asserta, assertz and assert, when calling the query.

Result: In the callback function show(), false is always getting printed out whenever asserting is attempted.

TermĀ {ref: 6065, id: "throw", args: Array(1), indicator: "throw/1"} is printed out whenever a query of chosen_meats(X). is done. However, normal predicate calling such as session.query("breads(X)."); gives the correct output at "[parmesan,honeywheat]", when tostring method is used.

Edit: Online Tau Prolog gives the same issue http://tau-prolog.org/ Error has been expanded as :

error parsing program: error(syntax_error('. or operator expected'), [line(1), column(11), found(client)])

for

:-dynamic client/1.

and

assertz(client(x)).
1

1 Answers

1
votes

The syntax error is the clue to the problem, you're missing some parenthesis. Only some Prolog dialects do not require them, so it's best practice to always include them for portability:

:- dynamic(chosen_meats/2).
?- asserta(chosen_meats(chicken, roast)).
true.

I put the solution in the sandbox, query test.: http://tau-prolog.org/sandbox/ZFgsdJkP