Skip to content

cuber-it/uc-prolog

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

uc-prolog

A Prolog interpreter implemented in Go and Python. WAM-based engine with ISO compliance, modules, streams, rational arithmetic, MCP server, and interactive REPL. Zero external dependencies.

Implementations

Go Python
Directory go-prolog/ py-prolog/
Install go build -o uc-prolog . pip install uc-prolog
Run ./uc-prolog --repl python3 -m uc_prolog --repl
Embed import "github.com/cuber-it/uc-prolog/go-prolog/prolog" from uc_prolog import Engine
MCP Server ./uc-prolog --port 4001 python3 -m uc_prolog --mcp
Binary Single static binary Pure Python, no C extensions

Both implementations share the same Prolog knowledge base (core/) and pass the same ISO compliance test suite (tests/).

Quick Start

parent(tom, bob).
parent(bob, ann).
grandparent(X, Z) :- parent(X, Y), parent(Y, Z).

?- grandparent(tom, X).
X = ann.

Embed in Python

from uc_prolog import Engine

engine = Engine()
engine.eval("parent(tom, bob).")
engine.eval("parent(bob, ann).")
engine.eval("grandparent(X, Z) :- parent(X, Y), parent(Y, Z).")
result = engine.eval("?- grandparent(tom, X).")
# result: "X = ann."

MCP Server

Expose Prolog as an MCP tool server — connect any LLM agent to a live knowledge base:

# Install with MCP support:
pip install uc-prolog[mcp]

# Start MCP server (stdio — for Claude Desktop etc.):
python3 -m uc_prolog --mcp

# Start MCP server (HTTP/SSE — for remote clients):
python3 -m uc_prolog --mcp --port 4003

Available MCP tools: prolog_eval, prolog_query, prolog_assert, prolog_load_file, prolog_status.

Architecture

uc-prolog/
  core/                  shared Prolog knowledge base (.prolog files)
    base.prolog          standard predicates: member, append, length, ...
    frames.prolog        frame-based knowledge representation
    refs.prolog          reference/pointer utilities
  tests/                 shared ISO compliance test suite (444 tests)
    iso_unification.plg
    iso_arithmetic.plg
    iso_control.plg
    iso_lists.plg
    iso_modules.plg
    iso_streams.plg
    iso_rational.plg
    ... (20 test files)
  web/                   shared web GUI (index.html)
  go-prolog/             Go reference implementation
  py-prolog/             Python implementation (PyPI: uc-prolog)

ISO Compliance

444 tests across 20 ISO Prolog categories — both implementations pass all of them:

Category Tests
Unification
Arithmetic
Control flow
Type checks
Lists
Database (assert/retract)
DCG
Modules
Stream I/O
Rational arithmetic
Flags

REST API

Both implementations serve the same HTTP API:

POST /api/eval          { "code": "parent(tom, bob)." }
POST /api/query         { "goal": "parent(tom, X)" }
GET  /api/listing       list all defined predicates
POST /api/reset         clear knowledge base
GET  /api/events        SSE stream

Tests

# Go
cd go-prolog && go test ./prolog/ -v

# Python
cd py-prolog && python3 -m pytest tests/ -v

License

Apache 2.0 — Ulrich Cuber / cuber IT service

About

Production-grade Prolog interpreter. Go reference + Python port. WAM solver, ISO compliance, MCP server

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors