Checkpoint

This commit is contained in:
Tibo De Peuter 2025-04-05 17:36:37 +02:00
parent 39c3af4ba5
commit da21d890fb
39 changed files with 1166 additions and 48 deletions

View file

@ -0,0 +1,35 @@
package prolog.components.expressions
import prolog.components.Functor
import prolog.components.Goal
import prolog.components.terms.Head
import prolog.components.terms.Term
import prolog.unify
// TODO Change this to the right type, supporting operators and normal Clauses
// Probably needs a new interface or abstract class (?)
typealias Body = List<Term>
/**
* Sentence of a Prolog program.
*
* A clause consists of a [Head] and body separated by the [neck][prolog.terms.Neck] operator, or it is a [Fact].
*
* @see [prolog.components.terms.Variable]
* @see [Predicate]
*/
abstract class Clause(val head: Head, val body: Body = emptyList()) : Expression {
val functor: Functor = head.functor
override fun evaluate(goal: Goal): Boolean {
val result = unify(goal, head)
// TODO Evaluate the body
return result.isEmpty
}
override fun toString(): String {
return when {
body.isEmpty() -> head.toString()
else -> "$head :- ${body.joinToString(", ")}"
}
}
}