if (node instanceof Node_RuleVariable) {
return environment[((Node_RuleVariable)node).getIndex()];
} else if (node instanceof Node_ANY) {
return null;
} else if (Functor.isFunctor(node)) {
Functor functor = (Functor)node.getLiteralValue();
if (functor.isGround()) return node;
Node[] args = functor.getArgs();
List<Node> boundargs = new ArrayList<>(args.length);
for ( Node arg : args )
{
Node binding = getBinding( arg );
if ( binding == null )
{
// Not sufficent bound to instantiate functor yet
return null;
}
boundargs.add( binding );
}
Functor newf = new Functor(functor.getName(), boundargs);
return Functor.makeFunctorNode( newf );
} else {
return node;
}
}