fix: Evaluation

This commit is contained in:
Tibo De Peuter 2025-04-06 17:29:23 +02:00
parent d702b9b081
commit 1acd1cfb67
Signed by: tdpeuter
GPG key ID: 38297DE43F75FFE2
17 changed files with 189 additions and 120 deletions

View file

@ -1,6 +1,6 @@
package prolog.components.expressions
import prolog.Substitution
import prolog.Substituted
import prolog.components.Resolvent
import prolog.components.terms.Functor
import prolog.components.terms.Goal
@ -49,12 +49,10 @@ class Predicate : Resolvent {
this.clauses.addAll(clauses)
}
override fun solve(goal: Goal): Sequence<Substitution> = sequence {
override fun solve(goal: Goal, subs: Substituted): Sequence<Substituted> = sequence {
require(goal.functor == functor) { "Goal functor does not match predicate functor" }
for (clause in clauses) {
// Try to unify the goal with the clause
// If the unification is successful, yield the substitutions
yieldAll(clause.solve(goal))
}
// Try to unify the goal with the clause
// If the unification is successful, yield the substitutions
clauses.forEach { yieldAll(it.solve(goal, subs)) }
}
}