package prolog.ast.terms

typealias Operand = Term

abstract class Operator(
    private val symbol: Atom,
    private val leftOperand: Operand? = null,
    private val rightOperand: Operand
) : CompoundTerm(symbol, listOfNotNull(leftOperand, rightOperand)), Term {
    constructor(symbol: String, leftOperand: Operand? = null, rightOperand: Operand) :
            this(Atom(symbol), leftOperand, rightOperand)

    override fun toString(): String {
        return when (leftOperand) {
            null -> "${symbol.name} $rightOperand"
            else -> "($leftOperand ${symbol.name} $rightOperand)"
        }
    }
}
