This commit is contained in:
Tibo De Peuter 2025-05-05 18:04:37 +02:00
parent a937b1bc44
commit fc8b83fca3
8 changed files with 117 additions and 19 deletions

View file

@ -9,12 +9,14 @@ import prolog.ast.terms.Body
import prolog.ast.terms.Goal
import prolog.ast.terms.Structure
import prolog.flags.AppliedCut
import prolog.logic.applySubstitution
/**
* Always fail.
*/
object Fail : Atom("fail"), Body {
override fun satisfy(subs: Substitutions): Answers = emptySequence()
override fun applySubstitution(subs: Substitutions): Fail = Fail
}
/**
@ -27,6 +29,7 @@ typealias False = Fail
*/
object True : Atom("true"), Body {
override fun satisfy(subs: Substitutions): Answers = sequenceOf(Result.success(emptyMap()))
override fun applySubstitution(subs: Substitutions): True = True
}
// TODO Repeat/0
@ -99,8 +102,8 @@ class Conjunction(val left: LogicOperand, private val right: LogicOperand) :
}
override fun applySubstitution(subs: Substitutions): Conjunction = Conjunction(
left.applySubstitution(subs) as LogicOperand,
right.applySubstitution(subs) as LogicOperand
applySubstitution(left, subs) as LogicOperand,
applySubstitution(right, subs) as LogicOperand
)
}
@ -114,10 +117,9 @@ open class Disjunction(private val left: LogicOperand, private val right: LogicO
yieldAll(right.satisfy(subs))
}
override fun clone(): Disjunction = Disjunction(left.clone() as LogicOperand, right.clone() as LogicOperand)
override fun applySubstitution(subs: Substitutions): Disjunction = Disjunction(
left.applySubstitution(subs) as LogicOperand,
right.applySubstitution(subs) as LogicOperand
applySubstitution(left, subs) as LogicOperand,
applySubstitution(right, subs) as LogicOperand
)
}
@ -141,4 +143,6 @@ class Not(private val goal: Goal) : LogicOperator(Atom("\\+"), rightOperand = go
// If the goal cannot be proven, return a sequence with an empty map
return sequenceOf(Result.success(emptyMap()))
}
override fun applySubstitution(subs: Substitutions): Not = Not(applySubstitution(goal, subs) as Goal)
}