Hello, Tau Prolog!
Imagine an internet where you could write Prolog...
Imagine no more, write Tau Prolog!
At PrologHub we're big fans of Tau Prolog, it provides all the interactive Prolog code on this website, so we thought we'd do a quick introduction.
console.log and by manipulating the DOM.
init predicate in your Prolog. You can find out more about this boiler-plate in the Tau-Prolog Simple Tutorial.
You'll also need to download
tau-prolog.js, in this template it's stored in the same root directory.
If you need a quick server, here's one in SWI-Prolog that'll get you up and running, query it with
swipl -g serve -s server.pl then navigate to localhost:8888:
Right, now we can make some "Hello, Tau-Prolog!" programs.
alert("Hello, Tau Prolog!")
library(js) are here. So our
code.pl in our template becomes:
And because we're running Tau Prolog, you can try it here too!
console.log("Hello, Tau Prolog!")
console.log is a little more involved because
log is a method of
console. It's a similar idea, there's some property called
console, which turns out to be an object, there's also a property of this object called
log, which turns out to be a function. Once we've got that function, we can apply it again.
Again we can query this here, but you'll need to open your console to see the results. How you open the console varies from browser to platform, but try
F12 before searching if you're unfamiliar.
Manipulating the DOM
Now we're getting to the more serious work. We're going to need library(dom), the docs for which are here. To do this we'll need to create a whole new HTML element and we'll make it a child element of
<div id="greet_answers">. So that you can run it here and it look quite pretty, we also add a couple of classes.
Now if you query it here you'll get an extra "Hello, Tau Prolog!" answer along with the usual
true ; false. answer. We made it blue to show it's not a usual successful or false answer.
This is only a "Hello, world!", there's much more goodness to discover! The great thing about Tau Prolog is it all runs client-side, so queries won't hog your server computing power, nor do you need to ensure predicates are safe on your server as you can do all of your reasoning without ever touching the server. Have fun!