/** * Dereference a node, following any binding trail. */ public static Node deref(Node node) { if (node instanceof Node_RuleVariable) { return ((Node_RuleVariable)node).deref(); } else { return node; } }
/** * Dereference a node, following any binding trail. */ public static Node deref(Node node) { if (node instanceof Node_RuleVariable) { return ((Node_RuleVariable)node).deref(); } else { return node; } }
/** * Unify two nodes. Current implementation does not support functors. * @return true if the unification succeeds */ public boolean unify(Node n1, Node n2) { Node nv1 = n1; if (nv1 instanceof Node_RuleVariable) { nv1 = ((Node_RuleVariable)n1).deref(); } Node nv2 = n2; if (nv2 instanceof Node_RuleVariable) { nv2 = ((Node_RuleVariable)n2).deref(); } if (nv1 instanceof Node_RuleVariable) { bind(nv1, nv2); return true; } else if (nv2 instanceof Node_RuleVariable) { bind(nv2, nv1); return true; } else { return nv1.sameValueAs(nv2); } }
/** * Unify two nodes. Current implementation does not support functors. * @return true if the unification succeeds */ public boolean unify(Node n1, Node n2) { Node nv1 = n1; if (nv1 instanceof Node_RuleVariable) { nv1 = ((Node_RuleVariable)n1).deref(); } Node nv2 = n2; if (nv2 instanceof Node_RuleVariable) { nv2 = ((Node_RuleVariable)n2).deref(); } if (nv1 instanceof Node_RuleVariable) { bind(nv1, nv2); return true; } else if (nv2 instanceof Node_RuleVariable) { bind(nv2, nv1); return true; } else { return nv1.sameValueAs(nv2); } }
/** * Bind a variable in the current environment to the given value. * Checks that the new binding is compatible with any current binding. * @param var a Node_RuleVariable defining the variable to bind * @param value the value to bind * @return false if the binding fails */ @Override public boolean bind(Node var, Node value) { Node dvar = var; if (dvar instanceof Node_RuleVariable) dvar = ((Node_RuleVariable)dvar).deref(); if (dvar instanceof Node_RuleVariable) { interpreter.bind(dvar, value); return true; } else { return var.sameValueAs(value); } }
/** * Bind a variable in the current environment to the given value. * Checks that the new binding is compatible with any current binding. * @param var a Node_RuleVariable defining the variable to bind * @param value the value to bind * @return false if the binding fails */ @Override public boolean bind(Node var, Node value) { Node dvar = var; if (dvar instanceof Node_RuleVariable) dvar = ((Node_RuleVariable)dvar).deref(); if (dvar instanceof Node_RuleVariable) { interpreter.bind(dvar, value); return true; } else { return var.sameValueAs(value); } }
Node dnode = ((Node_RuleVariable)node).deref(); if (dnode.isVariable()) {
Node dnode = ((Node_RuleVariable)node).deref(); if (dnode.isVariable()) {
ai = code[pc++]; arg = argVars[ai]; if (arg instanceof Node_RuleVariable) arg = ((Node_RuleVariable)arg).deref(); constant = (Node) args[ac++]; if (arg instanceof Node_RuleVariable) { boolean match = false; Node o = argVars[2]; if (o instanceof Node_RuleVariable) o = ((Node_RuleVariable)o).deref(); if (Functor.isFunctor(o)) { Functor funcArg = (Functor)o.getLiteralValue(); bind(((Node_RuleVariable)o).deref(), newFunc); match = true;
ai = code[pc++]; arg = argVars[ai]; if (arg instanceof Node_RuleVariable) arg = ((Node_RuleVariable)arg).deref(); constant = (Node) args[ac++]; if (arg instanceof Node_RuleVariable) { boolean match = false; Node o = argVars[2]; if (o instanceof Node_RuleVariable) o = ((Node_RuleVariable)o).deref(); if (Functor.isFunctor(o)) { Functor funcArg = (Functor)o.getLiteralValue(); bind(((Node_RuleVariable)o).deref(), newFunc); match = true;