Class InterpretedTailRecursivePredicate

java.lang.Object
org.projog.core.predicate.udp.TailRecursivePredicate
org.projog.core.predicate.udp.InterpretedTailRecursivePredicate
All Implemented Interfaces:
Predicate

final class InterpretedTailRecursivePredicate extends TailRecursivePredicate
A implementation of TailRecursivePredicate for interpreted user defined predicates.

The user defined predicate must be judged as eligible for tail recursion optimisation using the criteria used by TailRecursivePredicateMetaData.

See Also:
  • Field Details

    • isSpyPointEnabled

      private final boolean isSpyPointEnabled
    • spyPoint

      private final SpyPoints.SpyPoint spyPoint
    • numArgs

      private final int numArgs
    • currentQueryArgs

      private final Term[] currentQueryArgs
    • isRetryable

      private final boolean isRetryable
    • firstClausePredicateFactories

      private final PredicateFactory[] firstClausePredicateFactories
    • firstClauseConsequentArgs

      private final Term[] firstClauseConsequentArgs
    • firstClauseOriginalTerms

      private final Term[] firstClauseOriginalTerms
    • secondClausePredicateFactories

      private final PredicateFactory[] secondClausePredicateFactories
    • secondClauseConsequentArgs

      private final Term[] secondClauseConsequentArgs
    • secondClauseOriginalTerms

      private final Term[] secondClauseOriginalTerms
  • Constructor Details

    • InterpretedTailRecursivePredicate

      InterpretedTailRecursivePredicate(SpyPoints.SpyPoint spyPoint, Term[] inputArgs, PredicateFactory[] firstClausePredicateFactories, Term[] firstClauseConsequentArgs, Term[] firstClauseOriginalTerms, PredicateFactory[] secondClausePredicateFactories, Term[] secondClauseConsequentArgs, Term[] secondClauseOriginalTerms, boolean isRetryable)
  • Method Details

    • matchFirstRule

      protected boolean matchFirstRule()
      Description copied from class: TailRecursivePredicate
      Match the first rule of the tail recursive predicate.

      If the head of the first rule is matched then the rule has been successfully evaluated.

      Specified by:
      matchFirstRule in class TailRecursivePredicate
      Returns:
      true if the first rule is matched, else false
    • matchSecondRule

      protected boolean matchSecondRule()
      Description copied from class: TailRecursivePredicate
      Match the second rule of the tail recursive predicate.

      If the second rule is matched then the attempt at evaluating the rule continues for another level of recursion.

      Specified by:
      matchSecondRule in class TailRecursivePredicate
      Returns:
      true if the second rule is matched, else false
    • unify

      public static boolean unify(Term[] inputArgs, Term[] consequentArgs)
      Unifies the arguments in the head (consequent) of a clause with a query.

      When Prolog attempts to answer a query it searches its knowledge base for all rules with the same functor and arity. For each rule founds it attempts to unify the arguments in the query with the arguments in the head (consequent) of the rule. Only if the query and rule's head can be unified can it attempt to evaluate the body (antecedent) of the rule to determine if the rule is true.

      Parameters:
      inputArgs - the arguments contained in the query
      consequentArgs - the arguments contained in the head (consequent) of the clause
      Returns:
      true if the attempt to unify the arguments was successful
      See Also:
    • logCall

      protected void logCall()
      Specified by:
      logCall in class TailRecursivePredicate
    • logRedo

      protected void logRedo()
      Specified by:
      logRedo in class TailRecursivePredicate
    • logExit

      protected void logExit()
      Specified by:
      logExit in class TailRecursivePredicate
    • logFail

      protected void logFail()
      Specified by:
      logFail in class TailRecursivePredicate
    • backtrack

      protected void backtrack()
      Description copied from class: TailRecursivePredicate
      Backtracks the arguments to before the last attempt to match the first rule.
      Specified by:
      backtrack in class TailRecursivePredicate
    • couldReevaluationSucceed

      public boolean couldReevaluationSucceed()
      Description copied from interface: Predicate
      Could the next re-evaluation of this instance succeed?

      Specifies whether a specific instance of a specific implementation of Predicate, that has already had Predicate.evaluate() called on it at least once, could possibly return true the next time Predicate.evaluate() is called on it. i.e. is it worth trying to continue to find solutions for the specific query this particular instance represents and has been evaluating?

      (Note: the difference between this method and PredicateFactory.isRetryable() is that PredicateFactory.isRetryable() deals with whether, in general, a specific implementation (rather than instance) of Predicate could ever produce multiple answers for an individual query.)

      Returns:
      true if an attempt to re-evaluate this instance could possible succeed, false otherwise