/** * Determine whether a term is a functor. * * @param term The term to examine. * * @return <tt>true</tt> if the term is a functor, <tt>false</tt> if it is not. */ public boolean evaluate(Term term) { return term.isVar(); } }
/** * Determine whether a term is a functor. * * @param term The term to examine. * * @return <tt>true</tt> if the term is a functor, <tt>false</tt> if it is not. */ public boolean evaluate(Term term) { return term.isVar(); } }
/** * Gets the actual value of a term, which is either the term itself, or in the case of variables, the value that is * currently assigned to the variable. When the variable is free, the variable term itself is returned. * * @return The term itself, or the assigned value of this variable. */ public Term getValue() { Term result = this; Term assignment = this.substitution; // If the variable is assigned, loops down the chain of assignments until no more can be found. Whatever term // is found at the end of the chain of assignments is the value of this variable. while (assignment != null) { result = assignment; if (!assignment.isVar()) { break; } else { assignment = ((Variable) assignment).substitution; } } return result; }
/** * Gets the actual value of a term, which is either the term itself, or in the case of variables, the value that is * currently assigned to the variable. When the variable is free, the variable term itself is returned. * * @return The term itself, or the assigned value of this variable. */ public Term getValue() { Term result = this; Term assignment = this.substitution; // If the variable is assigned, loops down the chain of assignments until no more can be found. Whatever term // is found at the end of the chain of assignments is the value of this variable. while (assignment != null) { result = assignment; if (!assignment.isVar()) { break; } else { assignment = ((Variable) assignment).substitution; } } return result; }
/** * Determine whether a term is a free variable. * * @param term The object to test for predicate membership. * * @return <tt>true</tt> if the term is a free variable, <tt>false</tt> otherwise. */ public boolean evaluate(Term term) { if (term.isVar() && (term instanceof Variable)) { Variable var = (Variable) term; return !var.isBound(); } return false; } }
/** * Determine whether a term is a free variable. * * @param term The object to test for predicate membership. * * @return <tt>true</tt> if the term is a free variable, <tt>false</tt> otherwise. */ public boolean evaluate(Term term) { if (term.isVar() && (term instanceof Variable)) { Variable var = (Variable) term; return !var.isBound(); } return false; } }
/** * Evaluates a term by invoking its {@link Term#getValue()} method (which may cause a recursive evaluation, for * example, in the case of arithmetic expressions), and checks that the result is a fully instantiated numeric * value. * * @param numeric The term to evaluate as a number. * * @return The term as a number. */ static NumericType evaluateAsNumeric(Term numeric) { // Evaluate the expression. Term expressionValue = numeric.getValue(); // Ensure that the result of evaluating the expression is a number. if (expressionValue.isVar()) { throw new IllegalStateException("instantiation_error, 'is' expects a fully instantiated term to unify against."); } if (!expressionValue.isNumber()) { throw new IllegalStateException("arithmetic_error, 'is' expectes a numeric expression to unify against."); } return (NumericType) expressionValue; } }
/** * Determine whether a term is a free variable. * * @param term The object to test for predicate membership. * * @return <tt>true</tt> if the term is a free variable, <tt>false</tt> otherwise. */ public boolean evaluate(Term term) { if (term.isVar() && (term instanceof Variable)) { Variable var = (Variable) term; return !var.isBound() && !var.isAnonymous(); } return false; } }
/** * Determine whether a term is a free variable. * * @param term The object to test for predicate membership. * * @return <tt>true</tt> if the term is a free variable, <tt>false</tt> otherwise. */ public boolean evaluate(Term term) { if (term.isVar() && (term instanceof Variable)) { Variable var = (Variable) term; return !var.isBound() && !var.isAnonymous(); } return false; } }
if (argument.isVar())
if (argument.isVar())
/** {@inheritDoc} */ public boolean proofStep(ResolutionState state) { Functor goalTerm = state.getGoalStack().poll().getFunctor(); Term argument = goalTerm.getArgument(0).getValue(); // Check that the argument is not a free variable. if (argument.isVar()) { throw new IllegalStateException( "instantiation_error, 'call' expects a fully instantiated term to unify against."); } // Check that the argument is callable. if (!argument.isFunctor() && !argument.isAtom()) { throw new IllegalStateException("type_error, callable expected as argument to 'call'."); } // Set up the argument to call as a new goal. state.getGoalStack().offer(state.getBuiltInTransform().apply((Functor) argument)); return true; } }
else if (rightTerm.isVar() && ((Variable) rightTerm).isBound())
else if (rightTerm.isVar() && ((Variable) rightTerm).isBound())