package prolog.ast.terms

import prolog.Answers
import prolog.Substitutions
import prolog.ast.logic.Resolvent
import prolog.logic.unifyLazy
import prolog.ast.arithmetic.Integer

open class Atom(val name: String) : Goal(), Head, Body, Resolvent {
    override val functor: Functor = Functor(this, Integer(0))

    override fun solve(goal: Goal, subs: Substitutions): Answers = unifyLazy(goal, this, subs)

    override fun applySubstitution(subs: Substitutions): Atom = this

    override fun toString(): String {
        return name
    }

    override fun equals(other: Any?): Boolean {
        return (this === other) || (other is Atom && functor == other.functor)
    }

    override fun hashCode(): Int {
        return javaClass.hashCode()
    }
}