Functor
This commit is contained in:
parent
dff53b4e68
commit
65c4d925d3
15 changed files with 270 additions and 83 deletions
|
@ -1,8 +1,8 @@
|
|||
package prolog.ast.logic
|
||||
|
||||
import prolog.Answers
|
||||
import prolog.ast.Database.Program
|
||||
import prolog.Substitutions
|
||||
import prolog.ast.Database.Program
|
||||
import prolog.ast.terms.*
|
||||
import prolog.builtins.True
|
||||
import prolog.flags.AppliedCut
|
||||
|
@ -20,7 +20,7 @@ import prolog.logic.unifyLazy
|
|||
* @see [Predicate]
|
||||
*/
|
||||
abstract class Clause(var head: Head, var body: Body) : Term, Resolvent {
|
||||
val functor: Functor = head.functor
|
||||
val functor: FunctorInfo = 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.
|
||||
|
@ -45,7 +45,14 @@ abstract class Clause(var head: Head, var body: Body) : Term, Resolvent {
|
|||
onSuccess = { bodySubs ->
|
||||
// If the body can be proven, yield the (combined) substitutions
|
||||
val goalToHeadResult = goalToHeadSubs.mapValues { applySubstitution(it.value, bodySubs) }
|
||||
val headResult = headToGoalSubs.filterKeys { key -> goalToHeadSubs.any { occurs(key as Variable, it.value) } }
|
||||
val headResult = headToGoalSubs.filterKeys { key ->
|
||||
goalToHeadSubs.any {
|
||||
occurs(
|
||||
key as Variable,
|
||||
it.value
|
||||
)
|
||||
}
|
||||
}
|
||||
yield(Result.success(goalToHeadResult + headResult))
|
||||
},
|
||||
onFailure = { error ->
|
||||
|
|
Reference in a new issue