Checkpoint
This commit is contained in:
parent
e3c84e1761
commit
e73e5cbfc8
32 changed files with 1354 additions and 92 deletions
|
@ -1,8 +1,10 @@
|
|||
package prolog.ast.terms
|
||||
|
||||
import prolog.ast.arithmetic.Expression
|
||||
import prolog.logic.Substituted
|
||||
import java.util.*
|
||||
|
||||
data class Variable(val name: String) : Term {
|
||||
data class Variable(val name: String) : Term, Expression {
|
||||
private var alias: Optional<Term> = Optional.empty()
|
||||
|
||||
fun alias(): Optional<Term> {
|
||||
|
@ -21,6 +23,16 @@ data class Variable(val name: String) : Term {
|
|||
alias = Optional.empty()
|
||||
}
|
||||
|
||||
override fun evaluate(subs: Substituted): Pair<Term, Substituted> {
|
||||
// If the variable is bound, return the value of the binding
|
||||
// If the variable is not bound, return the variable itself
|
||||
return if (alias.isPresent) {
|
||||
alias.get().evaluate(subs)
|
||||
} else {
|
||||
Pair(this, emptyMap())
|
||||
}
|
||||
}
|
||||
|
||||
override fun compareTo(other: Term): Int {
|
||||
return when (other) {
|
||||
is Variable -> name.compareTo(other.name)
|
||||
|
|
Reference in a new issue