Checkpoint
This commit is contained in:
parent
43b364044e
commit
9db1c66781
34 changed files with 746 additions and 194 deletions
|
@ -1,10 +1,11 @@
|
|||
package prolog.ast.terms
|
||||
|
||||
import prolog.Answers
|
||||
import prolog.Substitutions
|
||||
import prolog.ast.arithmetic.Expression
|
||||
import prolog.ast.arithmetic.Simplification
|
||||
|
||||
data class Variable(val name: String) : Term, Expression {
|
||||
data class Variable(val name: String) : Term, Body, Expression {
|
||||
override fun simplify(subs: Substitutions): Simplification {
|
||||
// If the variable is bound, return the value of the binding
|
||||
// If the variable is not bound, return the variable itself
|
||||
|
@ -16,5 +17,15 @@ data class Variable(val name: String) : Term, Expression {
|
|||
return Simplification(this, result)
|
||||
}
|
||||
|
||||
override fun satisfy(subs: Substitutions): Answers {
|
||||
// If the variable is bound, satisfy the bound term
|
||||
if (this in subs) {
|
||||
val boundTerm = subs[this]!! as Body
|
||||
return boundTerm.satisfy(subs)
|
||||
}
|
||||
|
||||
return sequenceOf(Result.failure(IllegalArgumentException("Unbound variable: $this")))
|
||||
}
|
||||
|
||||
override fun toString(): String = name
|
||||
}
|
Reference in a new issue