Checkpoint
This commit is contained in:
parent
5bfa1691dd
commit
a85169dced
27 changed files with 377 additions and 250 deletions
|
@ -1,7 +1,7 @@
|
|||
package prolog.ast.logic
|
||||
|
||||
import prolog.Answers
|
||||
import prolog.Program
|
||||
import prolog.ast.Database.Program
|
||||
import prolog.Substitutions
|
||||
import prolog.ast.terms.*
|
||||
import prolog.builtins.True
|
||||
|
@ -16,10 +16,10 @@ import prolog.logic.unifyLazy
|
|||
*
|
||||
* A clause consists of a [Head] and body separated by the neck operator, or it is a [Fact].
|
||||
*
|
||||
* @see [prolog.ast.terms.Variable]
|
||||
* @see [Variable]
|
||||
* @see [Predicate]
|
||||
*/
|
||||
abstract class Clause(val head: Head, val body: Body) : Term, Resolvent {
|
||||
abstract class Clause(var head: Head, var body: Body) : Term, Resolvent {
|
||||
val functor: Functor = head.functor
|
||||
|
||||
override fun solve(goal: Goal, subs: Substitutions): Answers = sequence {
|
||||
|
@ -35,7 +35,7 @@ abstract class Clause(val head: Head, val body: Body) : Term, Resolvent {
|
|||
Program.variableRenamingStart = end
|
||||
|
||||
var newSubs: Substitutions = subs + renamed
|
||||
unifyLazy(goal, head, newSubs).forEach { headAnswer ->
|
||||
unifyLazy(applySubstitution(goal, subs), head, newSubs).forEach { headAnswer ->
|
||||
headAnswer.map { headSubs ->
|
||||
// If the body can be proven, yield the (combined) substitutions
|
||||
newSubs = subs + renamed + headSubs
|
||||
|
@ -43,8 +43,8 @@ abstract class Clause(val head: Head, val body: Body) : Term, Resolvent {
|
|||
bodyAnswer.fold(
|
||||
onSuccess = { bodySubs ->
|
||||
var result = (headSubs + bodySubs)
|
||||
.mapKeys { reverse[it.key] ?: it.key }
|
||||
.mapValues { reverse[it.value] ?: it.value }
|
||||
.mapKeys { applySubstitution(it.key, reverse)}
|
||||
.mapValues { applySubstitution(it.value, reverse) }
|
||||
result = result.map { it.key to applySubstitution(it.value, result) }
|
||||
.toMap()
|
||||
.filterNot { it.key in renamed.keys && !occurs(it.key as Variable, goal, emptyMap())}
|
||||
|
|
Reference in a new issue