-
-
Notifications
You must be signed in to change notification settings - Fork 0
env: Unifier
Eugene Lazutkin edited this page Dec 28, 2021
·
4 revisions
This is a technical class that is used as a marker (a base) for all unifiers. It defines no properties or methods. It is only purpose is to be used in the implementation of isUnifier().
It is defined in env and can be accessed like that:
import {Unifier} from 'deep6/env.js';
The current definition:
class Unifier {}
While Unifier
does not define any methods it is assumed that supported objects follow the Unifier
protocol and define the following method:
-
unify(val, ls, rs, env)
— a function that returns a boolean value to indicate success/failure of the unification. It takes the following arguments:-
val
— an arbitrary value to unify with. -
ls
— a stack of left arguments waiting to be unified at this point. -
rs
— a stack of right arguments corresponding tols
waiting to be unified at this point. -
env
— an environment to be used to resolve variables.
-
In most cases, the implementation pushes the appropriate values to ls
and rs
stacks and returns true
leaving the actual unification to be done later.
Example:
// a unifier to test values for 0
class IsZero extends Unifier {
unify(val, ls, rs, env) {
// shortcuts
if (val === 0 || val === any || val instanceof IsZero) return true;
// actual work
ls.push(0);
rs.push(val);
return true;
}
}