×ばつ callback/generator). Useful for pattern matching with extraction, constraint search, type inference, planners, expert systems, and policy checks. ESM, single runtime dependency (deep6). - Home · uhop/yopl Wiki"> ×ばつ callback/generator). Useful for pattern matching with..." /> ×ばつ callback/generator). Useful for pattern matching with..." />×ばつ callback/generator). Useful for pattern matching with..." />
Skip to content

Navigation Menu

Sign in
Sign up
Eugene Lazutkin edited this page May 9, 2026 · 15 revisions

Dashboard

Node.js CI NPM version

About

yopl is an ES6 mini-library that implements a Prolog-style logic solver in JavaScript. It provides:

  • A small core solver with multiple driver styles (callback, generator, async callback, async generator).
  • A built-in rule library: system helpers, comparisons, arithmetic, bitwise, and boolean logic.
  • Unification powered by deep6 — yopl's only runtime dependency, itself a zero-dependency library.

Installation

npm install --save yopl

Quick start

import {variable} from 'deep6/env.js';
import assemble from 'deep6/traverse/assemble.js';
import solve from 'yopl';
const rules = {
 member: [(V, X) => [{args: [{value: V, next: X}, V]}], (V, X) => [{args: [{next: X}, V]}, {name: 'member', args: [X, V]}]]
};
const list = {value: 1, next: {value: 2, next: {value: 3, next: null}}};
const X = variable('X');
solve(rules, 'member', [list, X], env => {
 console.log('X =', assemble(X, env));
});
// X = 1
// X = 2
// X = 3

Guides

  • Writing rules — a complete tutorial on rule anatomy, term builders, control predicates, and a worked example.

Module reference

Solvers

All four solvers share the same proof engine; they differ only in how they deliver solutions and whether they can await. Pick along two axes — sync vs async, push (callback) vs pull (generator):

Push (callback) Pull (generator)
Sync solve (main entry) solvers-gen
Async solvers-async solvers-asyncGen
  • Use an async solver when a goal predicate or your result handler must await.
  • Use a generator solver when you want lazy enumeration, early termination via break, or to compose solutions through iterator utilities.
  • Otherwise prefer solve — it has the lowest overhead.

See solve for the full motivation and shared rule shape.

Rule libraries

  • rules-system — built-in helpers and control predicates: head, term, list, cut, call, not, eq, true, fail, type predicates, etc.
  • rules-comp — comparisons: lt, le, gt, ge, nz.
  • rules-math — arithmetic: add, sub, mul, div, neg.
  • rules-bits — bitwise: bitAnd, bitOr, bitXor, bitNot.
  • rules-logic — boolean logic: logicalAnd, logicalOr, logicalXor, logicalNot.

Background

yopl is the next generation of heya-unify, based on an unpublished project named yoctoProlog. It implements Prolog-like logic-programming primitives without a dedicated language; the goal is an embedded JavaScript-native unifier and solver for tricky logic algorithms.

heya-unify was documented in a blog series:

Clone this wiki locally

AltStyle によって変換されたページ (->オリジナル) /