/** * 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); }
Term comparator = term.getValue();
Term comparator = term.getValue();
/** * 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; } }
/** * Compares this term for structural equality with another. Two terms are structurally equal if they are the same * functor with the same arguments, or are the same unbound variable, or the bound values of the left or right * variable operands are structurally equal. Structural equality is a stronger equality than unification and unlike * unification it does not produce any variable bindings. Two unified terms will always be structurally equal. * * @param term The term to compare with this one for structural equality. * * @return <tt>true</tt> if the two terms are structurally eqaul, <tt>false</tt> otherwise. */ public boolean structuralEquals(Term term) { Term comparator = term.getValue(); Term value = getValue(); // Check if this is an unbound variable in which case the comparator must be the same variable. if (value == this) { return this.equals(comparator); } else { return value.structuralEquals(comparator); } }
/** * Compares this term for structural equality with another. Two terms are structurally equal if they are the same * functor with the same arguments, or are the same unbound variable, or the bound values of the left or right * variable operands are structurally equal. Structural equality is a stronger equality than unification and unlike * unification it does not produce any variable bindings. Two unified terms will always be structurally equal. * * @param term The term to compare with this one for structural equality. * * @return <tt>true</tt> if the two terms are structurally eqaul, <tt>false</tt> otherwise. */ public boolean structuralEquals(Term term) { Term comparator = term.getValue(); Term value = getValue(); // Check if this is an unbound variable in which case the comparator must be the same variable. if (value == this) { return this.equals(comparator); } else { return value.structuralEquals(comparator); } }
/** {@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(); } }
/** {@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(); } }
Term consArgument = arguments[1].getValue();
Term consArgument = arguments[1].getValue();
/** * Prints a variable binding in the form 'Var = value'. * * @param var The variable to print. * * @return The variable binding in the form 'Var = value'. */ public String printVariableBinding(Term var) { return var.toString(getInterner(), true, false) + " = " + var.getValue().toString(getInterner(), false, true); }
Term presentAsTerm = fieldFunctor.getArgument(2).getValue(); Functor collectionKindFunctor = (Functor) fieldFunctor.getArgument(0).getValue(); String collectionKindName = engine.getFunctorName(collectionKindFunctor); String fieldName = engine.getFunctorName((Functor) fieldFunctor.getArgument(1).getValue()); String fieldTypeName = engine.getFunctorName((Functor) ((Functor) fieldFunctor.getArgument(2).getValue()).getArgument(1) .getValue()); engine.getFunctorName((Functor) collectionKindFunctor.getArgument(0).getValue());
/** {@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; } }
return unifyInternal(leftVar, rightTerm.getValue(), leftTrail, rightTrail);
return unifyInternal(leftVar, rightTerm.getValue(), leftTrail, rightTrail);