Clause
This commit is contained in:
parent
752c278cb0
commit
8bda3c5af4
15 changed files with 361 additions and 114 deletions
|
@ -20,7 +20,7 @@ import prolog.logic.unifyLazy
|
|||
* @see [Predicate]
|
||||
*/
|
||||
abstract class Clause(var head: Head, var body: Body) : Term, Resolvent {
|
||||
val functor: FunctorInfo = head.functor
|
||||
val functor: Functor = head.functor
|
||||
|
||||
override fun solve(goal: Goal, subs: Substitutions): Answers = sequence {
|
||||
// If the clause is a rule, unify the goal with the head and then try to prove the body.
|
||||
|
|
|
@ -2,25 +2,25 @@ package prolog.ast.logic
|
|||
|
||||
import prolog.Answers
|
||||
import prolog.Substitutions
|
||||
import prolog.ast.terms.FunctorInfo
|
||||
import prolog.ast.terms.Functor
|
||||
import prolog.ast.terms.Goal
|
||||
import prolog.flags.AppliedCut
|
||||
|
||||
/**
|
||||
* Collection of [Clause]s with the same [FunctorInfo].
|
||||
* Collection of [Clause]s with the same [Functor].
|
||||
*
|
||||
* If a goal is proved, the system looks for a predicate with the same functor, then uses indexing
|
||||
* to select candidate clauses and then tries these clauses one-by-one.
|
||||
*/
|
||||
class Predicate : Resolvent {
|
||||
val functor: FunctorInfo
|
||||
val functor: Functor
|
||||
val clauses: MutableList<Clause>
|
||||
var dynamic = false
|
||||
|
||||
/**
|
||||
* Creates a predicate with the given functor and an empty list of clauses.
|
||||
*/
|
||||
constructor(functor: FunctorInfo, dynamic: Boolean = false) {
|
||||
constructor(functor: Functor, dynamic: Boolean = false) {
|
||||
this.functor = functor
|
||||
this.clauses = mutableListOf()
|
||||
this.dynamic = dynamic
|
||||
|
|
Reference in a new issue