/** * Reports whether or not this term is a number. * * @return <tt>false</tt> always. */ public boolean isNumber() { Term t = getValue(); return (t != this) && t.isNumber(); }
/** * Reports whether or not this term is a number. * * @return <tt>false</tt> always. */ public boolean isNumber() { Term t = getValue(); return (t != this) && t.isNumber(); }
/** * Gets the actual value of a term, which is a numeric type equal in value to the arithmetic operator applied to its * arguments. This method checks that both arguments produce values which are fully instantiated and numeric when * their {@link Term#getValue()} methods are invoked. * * @return A numeric type equal in value to the the arithmetic operator applied to its arguments. */ public Term getValue() { Term firstArgValue = arguments[0].getValue(); Term secondArgValue = arguments[1].getValue(); // Check that the arguments to operate on are both numeric values. if (firstArgValue.isNumber() && secondArgValue.isNumber()) { return evaluate((NumericType) firstArgValue, (NumericType) secondArgValue); } else { return this; } }
/** * Gets the actual value of a term, which is a numeric type equal in value to the arithmetic operator applied to its * argument. This method checks that the argument produces a value which is fully instantiated and numeric when its * {@link Term#getValue()} methods is invoked. * * @return A numeric type equal in value to the the arithmetic operator applied to its argument. */ public NumericType getValue() { Term firstArgValue = arguments[0].getValue(); // Check that the argument to operate on is a numeric values. if (!firstArgValue.isNumber()) { throw new IllegalStateException( "instantiation_error, 'arithmetic/2' expects numeric arguments, but the first argument is non-numeric."); } return evaluate((NumericType) firstArgValue); }
/** * 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; } }
if (lengthTerm.isNumber())
/** {@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. return argument.isNumber() && ((NumericType) argument.getValue()).isReal(); } }
/** {@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. return argument.isNumber() && ((NumericType) argument.getValue()).isInteger(); } }