test: Cut not_equal
This commit is contained in:
parent
229a8bbc3c
commit
2fcab52f65
7 changed files with 75 additions and 18 deletions
|
@ -7,7 +7,7 @@ import prolog.ast.terms.Functor
|
|||
import prolog.ast.terms.Goal
|
||||
import prolog.ast.terms.Head
|
||||
import prolog.builtins.True
|
||||
import prolog.exceptions.AppliedCut
|
||||
import prolog.flags.AppliedCut
|
||||
import prolog.logic.unifyLazy
|
||||
|
||||
/**
|
||||
|
@ -36,7 +36,11 @@ abstract class Clause(private val head: Head, private val body: Body) : Resolven
|
|||
onFailure = { error ->
|
||||
if (error is AppliedCut) {
|
||||
// Find single solution and return immediately
|
||||
yield(Result.failure(AppliedCut(newHeadSubs + error.subs)))
|
||||
if (error.subs != null) {
|
||||
yield(Result.failure(AppliedCut(newHeadSubs + error.subs)))
|
||||
} else {
|
||||
yield(Result.failure(AppliedCut()))
|
||||
}
|
||||
return@sequence
|
||||
} else {
|
||||
yield(Result.failure(error))
|
||||
|
|
|
@ -4,7 +4,7 @@ import prolog.Answers
|
|||
import prolog.Substitutions
|
||||
import prolog.ast.terms.Functor
|
||||
import prolog.ast.terms.Goal
|
||||
import prolog.exceptions.AppliedCut
|
||||
import prolog.flags.AppliedCut
|
||||
|
||||
/**
|
||||
* Collection of [Clause]s with the same [Functor].
|
||||
|
@ -62,8 +62,10 @@ class Predicate : Resolvent {
|
|||
},
|
||||
onFailure = {
|
||||
if (it is AppliedCut) {
|
||||
// If it's a cut, yield the result with the left substitutions
|
||||
yield(Result.failure(AppliedCut(it.subs)))
|
||||
if (it.subs != null) {
|
||||
// If it's a cut, yield the result with the left substitutions
|
||||
yield(Result.success(it.subs))
|
||||
}
|
||||
return@sequence
|
||||
} else {
|
||||
yield(Result.failure(it))
|
||||
|
|
Reference in a new issue