
Tau-Prolog for LiaScript: Interactive Logic Programming in the Browser
- André Dietrich
- Template , Tutorial
- May 28, 2026
Prolog is the language of logic programming. Unlike imperative languages, Prolog programs describe what is true rather than how to compute it. This makes it essential in AI, natural language processing, theorem proving, and formal methods courses.
The Tau-Prolog template brings Tau-Prolog, a complete Prolog interpreter written in JavaScript, to LiaScript. Students load Prolog databases, run queries step by step, append rules incrementally, and even get quiz answers checked by the interpreter.
Quick Start
<!--
import: https://raw.githubusercontent.com/liaTemplates/tau-prolog/master/README.md
-->
Four macros form the core workflow: @Tau.program, @Tau.query, @Tau.program_append, and @Tau.check.
A convenience macro @Tau in the fence opener combines program and query in one block.
Macro 1: @Tau.program(id) — Load a Prolog Database
@Tau.program(id) consults (loads) a Prolog program into a named session.
Each named session is independent and persistent across the page.
```prolog family.pro
parent(tom, bob).
parent(tom, liz).
parent(bob, ann).
parent(bob, pat).
ancestor(X, Y) :- parent(X, Y).
ancestor(X, Y) :- parent(X, Z), ancestor(Z, Y).
```
@Tau.program(family.pro)
Macro 2: @Tau.query(id) — Query the Database
@Tau.query(id) queries the loaded session.
Click the run button to get the first answer; click again to get the next.
Each click returns one unification.
```prolog
ancestor(tom, X).
```
@Tau.query(family.pro)
Try it live — program and queries together:
Macro 3: @Tau.program_append(id) — Add Rules Incrementally
@Tau.program_append adds new facts and rules to an existing session without replacing the existing database.
This is ideal for lessons that build up a knowledge base step by step.
```prolog
% Extend the existing session with new rules
likes(alice, prolog).
likes(bob, python).
likes(alice, python).
speaks_same_language(X, Y) :-
likes(X, L), likes(Y, L), X \= Y.
```
@Tau.program_append(family.pro)
Convenience Macro: @Tau in Fence Opener
The @Tau(id, initial_query) fence opener creates both the program block and the query block from a single code block — useful for self-contained examples.
```prolog @Tau(holiday.pro,`goes_to(Who, france).`)
goes_to(axel, england).
goes_to(beate, greece).
goes_to(clemens, france).
goes_to(elmar, france).
```
Macro 4: @Tau.check — Prolog-Based Quiz Answers
@Tau.check(id, expected_query) checks a student’s text input against the loaded Prolog program.
This enables exercises where the correct answer can only be verified by logical evaluation — not string matching.
```prolog genealogy.pro
male(adam). male(alfred). male(bernd).
female(adele). female(anna). female(barbara).
parent(bernd, adam).
parent(bernd, adele).
parent(barbara, alfred).
parent(barbara, anna).
```
@Tau.program(genealogy.pro)
**Name one parent of alfred:**
[[parent(barbara, alfred).]]
@Tau.check(genealogy.pro, `setof(X, @'input, [alfred, anna])`)
Students type a Prolog query; @Tau.check evaluates it against the database and compares results with the expected solution.
Full Template Demo
Use Cases
Logic programming courses — Teach unification, backtracking, and the resolution principle with interactive examples. Students run queries step by step and see all solutions by clicking repeatedly.
AI and knowledge representation — Model family trees, ontologies, and expert system rules.
Tau-Prolog includes library(lists) for list processing (append/3, member/2, reverse/2, length/2).
Constraint solving exercises — Build puzzles like the famous N-Queens problem or map coloring as Prolog programs that students can query directly.
Prolog quizzes — Use @Tau.check to verify student answers at the semantic level.
Two equivalent Prolog queries return the same result, so students are not penalized for syntactic variation.
Incremental knowledge base building — Use @Tau.program_append across multiple sections of a course to demonstrate how a Prolog knowledge base grows as new facts and rules are added.
Technical Facts
| Runs in browser | Yes — Tau-Prolog (JavaScript) |
| Server required | No |
| Modules | library(lists) included |
| Sessions | Multiple named sessions per page |
| Backtracking | Yes — click repeatedly for next solution |
| Quiz integration | Yes — @Tau.check |
| Based on | Tau-Prolog by José Antonio Riaza Valverde |
| License | BSD-3 Clause |
| Maintained | Yes (version 0.3.1) |
Try It
Try in LiaScript Open in LiveEditor View on GitHubRelated Templates
- Curiosity-Prolog — lighter Prolog interpreter for simpler exercises
- BiwaScheme — Scheme/Lisp interpreter, another declarative language in the browser
- JSCPP — C++ in the browser for imperative-vs-declarative comparisons
- Pyodide — full Python, useful for AI and logic programming comparisons