×ばつ callback/generator). Useful for pattern matching with extraction, constraint search, type inference, planners, expert systems, and policy checks. ESM, single runtime dependency (deep6). - solve · 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 · 4 revisions

solve

Synchronous callback-style solver. The main public entry point of yopl.

Import

import solve from 'yopl';
// or: import solve from 'yopl/solve.js';

Signature

solve(rules, name, args, callback): void
Parameter Type Description
rules Rules Rule database (a {name: rule} object).
name string Initial goal name to prove.
args unknown[] Argument vector that unifies against the rule head.
callback (env: Env) => void Invoked once per solution.

The callback receives the live unification environment. Use assemble(variable, env) from deep6/traverse/assemble.js to extract bound values.

Example

import {variable} from 'deep6/env.js';
import assemble from 'deep6/traverse/assemble.js';
import solve from 'yopl';
const rules = {
 one: () => [{args: [1]}]
};
const X = variable('X');
solve(rules, 'one', [X], env => {
 console.log(assemble(X, env)); // 1
});

Rule shape

A rule is a function (or array of functions for a disjunction) that receives a fresh batch of logical variables and returns an array of terms. The first term is the rule head ({args: [...]}); the rest are body goals.

const rules = {
 member: [(V, X) => [{args: [{value: V, next: X}, V]}], (V, X) => [{args: [{next: X}, V]}, {name: 'member', args: [X, V]}]]
};

A body goal can be:

  • a structured term: {name: 'member', args: [X, V]}
  • a bare string (rule name with no args): 'true'
  • an inline JS function (env, goals, stack) => boolean | GoalFrame for predicates implemented directly in JavaScript.

See rules-system for helpers (head, term, list, cut, call, ...) that build these shapes ergonomically.

Clone this wiki locally

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