IO Operators

This commit is contained in:
Tibo De Peuter 2025-04-27 20:11:15 +02:00
parent b9f419a59d
commit 82a8fccf87
Signed by: tdpeuter
GPG key ID: 38297DE43F75FFE2
22 changed files with 450 additions and 199 deletions

View file

@ -6,7 +6,7 @@ abstract class Operator(
private val symbol: Atom,
private val leftOperand: Operand? = null,
private val rightOperand: Operand
) : CompoundTerm(symbol, listOfNotNull(leftOperand, rightOperand)) {
) : CompoundTerm(symbol, listOfNotNull(leftOperand, rightOperand)), Term {
override fun toString(): String {
return when (leftOperand) {
null -> "${symbol.name} $rightOperand"

View file

@ -22,4 +22,15 @@ open class Structure(val name: Atom, var arguments: List<Argument>) : Goal(), He
else -> "${name.name}(${arguments.joinToString(", ")})"
}
}
}
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other !is Structure) return false
if (functor != other.functor) return false
return arguments.zip(other.arguments).all { (a, b) -> a == b }
}
override fun hashCode(): Int {
return javaClass.hashCode()
}
}