Checkpoint

This commit is contained in:
Tibo De Peuter 2025-04-06 12:14:18 +02:00
parent 438af6c053
commit 6eca9dfcb7
Signed by: tdpeuter
GPG key ID: 38297DE43F75FFE2
25 changed files with 309 additions and 113 deletions

View file

@ -1,11 +1,16 @@
package prolog.builtins
import prolog.components.expressions.Operand
import prolog.components.expressions.Operator
import prolog.components.terms.Atom
import prolog.components.terms.Body
/**
* Always fail.
*/
class Fail: Atom("fail")
class Fail: Atom("fail"), Body {
override fun prove(): Boolean = false
}
/**
* Same as fail, but the name has a more declarative connotation.
@ -15,6 +20,32 @@ typealias False = Fail
/**
* Always succeed.
*/
class True: Atom("true")
class True: Atom("true"), Body {
override fun prove(): Boolean = true
}
// TODO Repeat/0
// TODO !/0 (Cut)
/**
* Conjunction (and). True if both Goal1 and Goal2 are true.
*/
class Conjunction(leftOperand: Operand, rightOperand: Operand) : Operator(Atom(","), leftOperand, rightOperand) {
override fun prove(): Boolean {
val left = leftOperand?.prove() ?: true
val right = rightOperand.prove()
return left && right
}
}
/**
* Disjunction (or). True if either Goal1 or Goal2 succeeds.
*/
class Disjunction(leftOperand: Operand, rightOperand: Operand) : Operator(Atom(";"), leftOperand, rightOperand) {
override fun prove(): Boolean {
val left = leftOperand?.prove() ?: false
val right = rightOperand.prove()
return left || right
}
}