DEV Community

artydev
artydev

Posted on • Edited on

1

Simple Tau-Prolog program

Simple Tau-Prolog


let session = pl.create(1000);

let program = `
    parent(john, mary).
    parent(susan, mary).

    parent(mary, alice).
    parent(mary, bob).

    grandparent(X, Y) :- parent(X, Z), parent(Z, Y).
    sibling(X, Y) :- parent(Z, X), parent(Z, Y), X \\= Y.
    ancestor(X, Y) :- parent(X, Y).
    ancestor(X, Y) :- parent(X, Z), ancestor(Z, Y).
`;

 function showAnswer (a) {
   console.log(a)
 }

 session.consult(program, {
    success: function() {
        session.query("grandparent(X, bob).", {
            success: function(goal) {
                session.answers(showAnswer);
            } 
        }); 
    }
});
Enter fullscreen mode Exit fullscreen mode

Demo TauProlog

AWS Q Developer image

Your AI Code Assistant

Automate your code reviews. Catch bugs before your coworkers. Fix security issues in your code. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay