All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.it.unibo.tuprolog.theory.RetractResult.kt Maven / Gradle / Ivy

Go to download

In-memory storage and indexing facilities for ordered and unordered knowledge bases composed by logic clauses

There is a newer version: 1.0.4
Show newest version
package it.unibo.tuprolog.theory

import it.unibo.tuprolog.core.Clause
import kotlin.js.JsName

/** A result given after a "retract" operation */
sealed class RetractResult {
    open val isSuccess: Boolean
        get() = false

    open val isFailure: Boolean
        get() = false

    /** The result always present value, is the clause database resulting from the operation execution */
    @JsName("theory")
    abstract val theory: T

    @JsName("clauses")
    abstract val clauses: Iterable?

    /** Gets the first successfully retracted clause */
    @JsName("firstClause")
    abstract val firstClause: Clause?

    /** A successful "retract" operation result, carrying the new [theory] and removed [clauses] */
    data class Success(
        override val theory: T,
        override val clauses: Iterable,
    ) : RetractResult() {
        override val isSuccess: Boolean
            get() = true

        override val firstClause: Clause
            get() = clauses.first()
    }

    /** A failed "retract" operation result, carrying the unchanged [theory] */
    data class Failure(override val theory: T) : RetractResult() {
        override val isFailure: Boolean
            get() = true

        override val clauses: Nothing?
            get() = null

        override val firstClause: Nothing?
            get() = null
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy