en un clic
add-unifier
// Add a new unifier module to deep6. Use when asked to create custom pattern matching logic or extend unification behavior.
// Add a new unifier module to deep6. Use when asked to create custom pattern matching logic or extend unification behavior.
| name | add-unifier |
| description | Add a new unifier module to deep6. Use when asked to create custom pattern matching logic or extend unification behavior. |
Create a new unifier that extends deep6's pattern matching capabilities.
Create the unifier file at src/unifiers/foo.js:
Unifier from ../env.jsUnifierunify(val, ls, rs, env) methodExample structure:
import {Unifier, isVariable} from '../env.js';
class MyUnifier extends Unifier {
constructor(options) {
super();
this.options = options;
}
unify(val, ls, rs, env) {
// Return true for match, false for failure
// Push to ls/rs to continue unification with sub-values
if (isVariable(val)) return false;
// Your matching logic here
return true;
}
}
const myUnifier = options => new MyUnifier(options);
export {MyUnifier};
export default myUnifier;
Add tests in tests/tests.js:
import myUnifier from '../src/unifiers/myUnifier.js';Run tests: npm test
Create wiki documentation at wiki/myUnifier.md:
Update wiki/Home.md — Add link under Unifiers section
Update ARCHITECTURE.md:
Update llms.txt and llms-full.txt:
Verify: npm test
MatchString, MyUnifier)matchString, myUnifier)matchString.js, myUnifier.js)Unifier class from env.jsunify(val, ls, rs, env) methodtrue for success, false for failurels.push() and rs.push() to queue sub-value comparisonsisVariable(val) if variables should not match directlyunify(val, ls, rs, env) {
return typeof val === 'number' && val > 0;
}
unify(val, ls, rs, env) {
ls.push(this.capture);
rs.push(val);
return true;
}
unify(val, ls, rs, env) {
ls.push(this.pattern);
rs.push(val);
return true; // Continue unification with pushed values
}
src/unifiers/Unifier base class: src/env.jssrc/unify.jsUse the deep6 library for deep equality, deep cloning, unification, and pattern matching with logical variables in a JavaScript/TypeScript project. Use when adding structural comparison, structured clone with circular references, extensible pattern matching with extraction, or unification-based logic to a project that depends on `deep6`.
Write or update tests for a module or feature. Use when asked to write tests, add test coverage, or verify functionality for deep6.
Add support for a new type to unify and clone registries. Use when asked to support a new JavaScript type or custom class in deep6.
Debug unification failures in deep6. Use when unification returns null or produces unexpected results.