-
-
Notifications
You must be signed in to change notification settings - Fork 0
Home
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.
npm install --save yopl
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
- Writing rules — a complete tutorial on rule anatomy, term builders, control predicates, and a worked example.
- 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.
-
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.
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: