Class InterpretedTailRecursivePredicate
- All Implemented Interfaces:
Predicate
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 Summary
FieldsModifier and TypeFieldDescriptionprivate final Term[]private final Term[]private final Term[]private final PredicateFactory[]private final booleanprivate final booleanprivate final intprivate final Term[]private final Term[]private final PredicateFactory[]private final SpyPoints.SpyPoint -
Constructor Summary
ConstructorsConstructorDescriptionInterpretedTailRecursivePredicate(SpyPoints.SpyPoint spyPoint, Term[] inputArgs, PredicateFactory[] firstClausePredicateFactories, Term[] firstClauseConsequentArgs, Term[] firstClauseOriginalTerms, PredicateFactory[] secondClausePredicateFactories, Term[] secondClauseConsequentArgs, Term[] secondClauseOriginalTerms, boolean isRetryable) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidBacktracks the arguments to before the last attempt to match the first rule.booleanCould the next re-evaluation of this instance succeed?protected voidlogCall()protected voidlogExit()protected voidlogFail()protected voidlogRedo()protected booleanMatch the first rule of the tail recursive predicate.protected booleanMatch the second rule of the tail recursive predicate.static booleanUnifies the arguments in the head (consequent) of a clause with a query.Methods inherited from class TailRecursivePredicate
evaluate
-
Field Details
-
isSpyPointEnabled
private final boolean isSpyPointEnabled -
spyPoint
-
numArgs
private final int numArgs -
currentQueryArgs
-
isRetryable
private final boolean isRetryable -
firstClausePredicateFactories
-
firstClauseConsequentArgs
-
firstClauseOriginalTerms
-
secondClausePredicateFactories
-
secondClauseConsequentArgs
-
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: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
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:
-
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
-