Checkpoint
This commit is contained in:
parent
23b2ce9362
commit
f9017da734
18 changed files with 814 additions and 412 deletions
17
src/prolog/ast/terms/AnonymousVariable.kt
Normal file
17
src/prolog/ast/terms/AnonymousVariable.kt
Normal file
|
@ -0,0 +1,17 @@
|
|||
package prolog.ast.terms
|
||||
|
||||
import io.Logger
|
||||
|
||||
class AnonymousVariable(id: Int) : Variable("_$id") {
|
||||
companion object {
|
||||
private var counter = 0
|
||||
fun create(): AnonymousVariable {
|
||||
val id = counter
|
||||
counter++
|
||||
Logger.debug("Creating anonymous variable: _${id}")
|
||||
return AnonymousVariable(id)
|
||||
}
|
||||
}
|
||||
|
||||
override fun toString(): String = "_"
|
||||
}
|
|
@ -6,7 +6,7 @@ import prolog.ast.arithmetic.Expression
|
|||
import prolog.ast.arithmetic.Simplification
|
||||
import prolog.ast.logic.LogicOperand
|
||||
|
||||
data class Variable(val name: String) : Term, Body, Expression, LogicOperand() {
|
||||
open class Variable(val name: String) : Term, Body, Expression, LogicOperand() {
|
||||
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
|
||||
|
@ -28,5 +28,15 @@ data class Variable(val name: String) : Term, Body, Expression, LogicOperand() {
|
|||
return sequenceOf(Result.failure(IllegalArgumentException("Unbound variable: $this")))
|
||||
}
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (other == null || other !is Variable) return false
|
||||
return name == other.name
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
return name.hashCode()
|
||||
}
|
||||
|
||||
override fun toString(): String = name
|
||||
}
|
Reference in a new issue