Checkpoint
This commit is contained in:
parent
ef8b82457c
commit
d702b9b081
13 changed files with 114 additions and 63 deletions
|
@ -1,5 +1,6 @@
|
|||
package prolog.components.expressions
|
||||
|
||||
import prolog.Substitution
|
||||
import prolog.components.Resolvent
|
||||
import prolog.components.terms.Functor
|
||||
import prolog.components.terms.Goal
|
||||
|
@ -48,8 +49,12 @@ class Predicate : Resolvent {
|
|||
this.clauses.addAll(clauses)
|
||||
}
|
||||
|
||||
override fun solve(goal: Goal): Boolean {
|
||||
override fun solve(goal: Goal): Sequence<Substitution> = sequence {
|
||||
require(goal.functor == functor) { "Goal functor does not match predicate functor" }
|
||||
return clauses.any { it.solve(goal) }
|
||||
for (clause in clauses) {
|
||||
// Try to unify the goal with the clause
|
||||
// If the unification is successful, yield the substitutions
|
||||
yieldAll(clause.solve(goal))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue