Curiosity-Prolog for LiaScript: Lightweight Logic Programming in the Browser

Curiosity-Prolog for LiaScript: Lightweight Logic Programming in the Browser

Not every logic programming exercise needs a full Prolog system. For introductory exercises — family trees, simple rule-based reasoning, first-order logic — a lighter interpreter is often more appropriate.

The Curiosity-Prolog template provides a minimal Prolog interpreter based on curiosity-driven.github.io/prolog-interpreter. It is smaller and simpler than Tau-Prolog, which makes it useful for quick demonstrations and exercises where the full feature set of standard Prolog is not needed.

For a fully functional Prolog implementation with module support, library(lists), and quiz integration, see the Tau-Prolog template.


Quick Start

<!--
import: https://raw.githubusercontent.com/liaTemplates/curiosity-prolog/master/README.md
-->

Three macros: @Prolog.db, @Prolog.shell, and @Prolog.ui in the fence opener.


Macro 1: @Prolog.db(id) — Load a Prolog Database

@Prolog.db(id) loads (consults) a Prolog program into a named session. The session name is the shared identifier used to connect the database to queries.

```prolog mydb
parent(alice, charlie).
parent(alice, diana).
parent(bob, charlie).
parent(bob, diana).

grandparent(X, Z) :- parent(X, Y), parent(Y, Z).
```
@Prolog.db(mydb)

Macro 2: @Prolog.shell(id) — Query the Database

@Prolog.shell(id) creates an interactive shell for querying the named database. Students type queries and get answers.

```prolog
parent(alice, X).
```
@Prolog.shell(mydb)

The two macros together define the basic workflow: load a knowledge base with @Prolog.db, then explore it with @Prolog.shell.


Convenience Macro: @Prolog.ui in Fence Opener

The @Prolog.ui(id, initial_query) macro in the fence opener combines database and shell into one block. The program is loaded when run, and the initial query is executed immediately.

```prolog @Prolog.ui(shapes, `has_sides(X, 4).`)
has_sides(triangle, 3).
has_sides(square, 4).
has_sides(pentagon, 5).
has_sides(hexagon, 6).

regular(square).
regular(triangle).

shape(X) :- has_sides(X, _).
```

This is ideal for self-contained demonstrations where you want the student to see both the rules and the initial query result at a glance.


Full Template Demo


Use Cases

First Prolog exposure — Introduce the concepts of facts, rules, and queries with a minimal interface. The lighter interpreter reduces cognitive overhead for students who are encountering logic programming for the first time.

Knowledge representation exercises — Model simple domains — animals, shapes, family relationships, geography — as Prolog fact bases and ask students to write queries.

Declarative vs imperative comparisons — Use side-by-side examples to show how the same problem is expressed imperatively (in Python or JavaScript) and declaratively (in Prolog).

Quick in-lecture demos — Curiosity-Prolog’s lightweight nature makes it fast to load and responsive for short interactive demonstrations during lectures.


Curiosity-Prolog vs. Tau-Prolog

FeatureCuriosity-PrologTau-Prolog
Interpreter sizeSmall, fast to loadLarger, more complete
Standard libraryNonelibrary(lists)
Module supportNoYes
Quiz integrationNoYes (@Tau.check)
Incremental loadingNoYes (@Tau.program_append)
Best forIntroductory exercisesAdvanced logic programming

Technical Facts

Runs in browserYes
Server requiredNo
SessionsMultiple named sessions per page
Based oncuriosity-driven.github.io/prolog-interpreter
LicenseCC0 1.0 Public Domain
MaintainedStable (version 0.0.2)

Try It

Try in LiaScript Open in LiveEditor View on GitHub
  • Tau-Prolog — full-featured Prolog with module support and quiz integration
  • BiwaScheme — Scheme interpreter for functional and declarative programming
  • JSCPP — C++ interpreter for contrast with imperative programming

Related Posts

BiwaScheme for LiaScript: Functional Programming with Scheme in the Browser

Use the BiwaScheme template to run Scheme programs in your LiaScript courses — a complete Scheme interpreter in the browser, with an optional interactive REPL terminal.

Read More

LogicEmu for LiaScript: ASCII Logic Circuits That Actually Run

Draw logic circuits as ASCII diagrams and run them live in LiaScript — using the LogicEmu template backed by Lode Vandevenne's logicemu simulator. No JSON, no schematic editor needed.

Read More

CodeRunner for LiaScript: Execute Code in 50+ Languages Server-Side

Run Python, Java, C, C++, Ruby, Rust, Go, Haskell, and 40+ more languages directly inside LiaScript courses via a server-side code runner — no browser limitations, real compilers.

Read More