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 ofTailRecursivePredicatefor interpreted user defined predicates.The user defined predicate must be judged as eligible for tail recursion optimisation using the criteria used by
TailRecursivePredicateMetaData.
-
-
Field Summary
Fields Modifier and Type Field Description private Term[]currentQueryArgsprivate Term[]firstClauseConsequentArgsprivate Term[]firstClauseOriginalTermsprivate PredicateFactory[]firstClausePredicateFactoriesprivate booleanisRetryableprivate booleanisSpyPointEnabledprivate intnumArgsprivate Term[]secondClauseConsequentArgsprivate Term[]secondClauseOriginalTermsprivate PredicateFactory[]secondClausePredicateFactoriesprivate SpyPoints.SpyPointspyPoint
-
Constructor Summary
Constructors Constructor Description InterpretedTailRecursivePredicate(SpyPoints.SpyPoint spyPoint, Term[] inputArgs, PredicateFactory[] firstClausePredicateFactories, Term[] firstClauseConsequentArgs, Term[] firstClauseOriginalTerms, PredicateFactory[] secondClausePredicateFactories, Term[] secondClauseConsequentArgs, Term[] secondClauseOriginalTerms, boolean isRetryable)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidbacktrack()Backtracks the arguments to before the last attempt to match the first rule.booleancouldReevaluationSucceed()Could the next re-evaluation of this instance succeed?protected voidlogCall()protected voidlogExit()protected voidlogFail()protected voidlogRedo()protected booleanmatchFirstRule()Match the first rule of the tail recursive predicate.protected booleanmatchSecondRule()Match the second rule of the tail recursive predicate.static booleanunify(Term[] inputArgs, Term[] consequentArgs)Unifies the arguments in the head (consequent) of a clause with a query.-
Methods inherited from class org.projog.core.predicate.udp.TailRecursivePredicate
evaluate
-
-
-
-
Field Detail
-
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 Detail
-
InterpretedTailRecursivePredicate
InterpretedTailRecursivePredicate(SpyPoints.SpyPoint spyPoint, Term[] inputArgs, PredicateFactory[] firstClausePredicateFactories, Term[] firstClauseConsequentArgs, Term[] firstClauseOriginalTerms, PredicateFactory[] secondClausePredicateFactories, Term[] secondClauseConsequentArgs, Term[] secondClauseOriginalTerms, boolean isRetryable)
-
-
Method Detail
-
matchFirstRule
protected boolean matchFirstRule()
Description copied from class:TailRecursivePredicateMatch 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:
matchFirstRulein classTailRecursivePredicate- Returns:
trueif the first rule is matched, elsefalse
-
matchSecondRule
protected boolean matchSecondRule()
Description copied from class:TailRecursivePredicateMatch 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:
matchSecondRulein classTailRecursivePredicate- Returns:
trueif the second rule is matched, elsefalse
-
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 queryconsequentArgs- the arguments contained in the head (consequent) of the clause- Returns:
trueif the attempt to unify the arguments was successful- See Also:
Term.unify(Term)
-
logCall
protected void logCall()
- Specified by:
logCallin classTailRecursivePredicate
-
logRedo
protected void logRedo()
- Specified by:
logRedoin classTailRecursivePredicate
-
logExit
protected void logExit()
- Specified by:
logExitin classTailRecursivePredicate
-
logFail
protected void logFail()
- Specified by:
logFailin classTailRecursivePredicate
-
backtrack
protected void backtrack()
Description copied from class:TailRecursivePredicateBacktracks the arguments to before the last attempt to match the first rule.- Specified by:
backtrackin classTailRecursivePredicate
-
couldReevaluationSucceed
public boolean couldReevaluationSucceed()
Description copied from interface:PredicateCould the next re-evaluation of this instance succeed?Specifies whether a specific instance of a specific implementation of
Predicate, that has already hadPredicate.evaluate()called on it at least once, could possibly returntruethe next timePredicate.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 thatPredicateFactory.isRetryable()deals with whether, in general, a specific implementation (rather than instance) ofPredicatecould ever produce multiple answers for an individual query.)- Returns:
trueif an attempt to re-evaluate this instance could possible succeed,falseotherwise
-
-