×ばつ 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 Apr 7, 2026 · 15 revisions

yopl

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

  • solve — synchronous callback-style solver (the main entry).
  • solvers-gen — synchronous generator-based solver.
  • solvers-async — asynchronous callback-style solver.
  • solvers-asyncGen — asynchronous generator-based solver.

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 によって変換されたページ (->オリジナル) /