Checkpoint

This commit is contained in:
Tibo De Peuter 2025-04-06 14:42:57 +02:00
parent ef8b82457c
commit d702b9b081
Signed by: tdpeuter
GPG key ID: 38297DE43F75FFE2
13 changed files with 114 additions and 63 deletions

View file

@ -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))
}
}
}