commonMain.it.unibo.tuprolog.solve.SideEffect.kt Maven / Gradle / Ivy
package it.unibo.tuprolog.solve
import it.unibo.tuprolog.core.Clause
import it.unibo.tuprolog.core.Term
import it.unibo.tuprolog.core.operators.Operator
import it.unibo.tuprolog.core.operators.OperatorSet
import it.unibo.tuprolog.solve.channel.InputChannel
import it.unibo.tuprolog.solve.channel.OutputChannel
import it.unibo.tuprolog.solve.library.AliasedLibrary
import it.unibo.tuprolog.solve.library.Libraries
import it.unibo.tuprolog.solve.library.Library
import it.unibo.tuprolog.theory.Theory
sealed class SideEffect {
data class ResetStaticKb(val clauses: Iterable) : SideEffect() {
constructor(vararg clauses: Clause) : this(listOf(*clauses))
constructor(clauses: Sequence) : this(clauses.asIterable())
val theory by lazy {
if (clauses is Theory) {
clauses
} else {
Theory.indexedOf(clauses)
}
}
}
data class AddStaticClauses(val clauses: Iterable, val onTop: Boolean = false) : SideEffect() {
constructor(vararg clauses: Clause, onTop: Boolean = false) : this(listOf(*clauses), onTop)
constructor(clauses: Sequence, onTop: Boolean = false) : this(clauses.asIterable(), onTop)
}
data class RemoveStaticClauses(val clauses: Iterable) : SideEffect() {
constructor(vararg clauses: Clause) : this(listOf(*clauses))
constructor(clauses: Sequence) : this(clauses.asIterable())
}
data class ResetDynamicKb(val clauses: Iterable) : SideEffect() {
constructor(vararg clauses: Clause) : this(listOf(*clauses))
constructor(clauses: Sequence) : this(clauses.asIterable())
val theory by lazy {
if (clauses is Theory) {
clauses
} else {
Theory.indexedOf(clauses)
}
}
}
data class AddDynamicClauses(val clauses: Iterable, val onTop: Boolean = false) : SideEffect() {
constructor(vararg clauses: Clause, onTop: Boolean = false) : this(listOf(*clauses), onTop)
constructor(clauses: Sequence, onTop: Boolean = false) : this(clauses.asIterable(), onTop)
}
data class RemoveDynamicClauses(val clauses: Iterable) : SideEffect() {
constructor(vararg clauses: Clause) : this(listOf(*clauses))
constructor(clauses: Sequence) : this(clauses.asIterable())
}
data class SetFlags(val flags: Map) : SideEffect() {
constructor(vararg flags: Pair) : this(listOf(*flags))
constructor(flags: Iterable>) : this(flags.toMap())
constructor(flags: Sequence>) : this(flags.toMap())
}
data class ResetFlags(val flags: Map) : SideEffect() {
constructor(vararg flags: Pair) : this(listOf(*flags))
constructor(flags: Iterable>) : this(flags.toMap())
constructor(flags: Sequence>) : this(flags.toMap())
}
data class ClearFlags(val names: Iterable) : SideEffect() {
constructor(vararg names: String) : this(listOf(*names))
constructor(names: Sequence) : this(names.toList())
}
data class LoadLibrary(val alias: String, val library: Library) : SideEffect() {
init {
when (val lib = library) {
is AliasedLibrary -> require(lib.alias == alias)
}
}
val aliasedLibrary: AliasedLibrary by lazy {
if (library is AliasedLibrary) {
library
} else {
Library.of(library, alias)
}
}
}
data class UnloadLibraries(val aliases: List) : SideEffect() {
constructor(aliases: Iterable) : this(aliases.toList())
constructor(aliases: Sequence) : this(aliases.toList())
constructor(vararg aliases: String) : this(listOf(*aliases))
}
data class UpdateLibrary(val alias: String, val library: Library) : SideEffect() {
init {
when (val lib = library) {
is AliasedLibrary -> require(lib.alias == alias)
}
}
val aliasedLibrary: AliasedLibrary by lazy {
if (library is AliasedLibrary) {
library
} else {
Library.of(library, alias)
}
}
}
data class AddLibraries(val libraries: Libraries) : SideEffect() {
constructor(libraries: Iterable) : this(Libraries(libraries))
constructor(libraries: Sequence) : this(Libraries(libraries))
constructor(vararg libraries: AliasedLibrary) : this(Libraries(*libraries))
}
data class ResetLibraries(val libraries: Libraries) : SideEffect() {
constructor(libraries: Iterable) : this(Libraries(libraries))
constructor(libraries: Sequence) : this(Libraries(libraries))
constructor(vararg libraries: AliasedLibrary) : this(Libraries(*libraries))
}
data class SetOperators(val operators: Iterable) : SideEffect() {
constructor(vararg operators: Operator) : this(listOf(*operators))
constructor(operators: Sequence) : this(operators.toOperatorSet())
val operatorSet: OperatorSet by lazy {
if (operators is OperatorSet) {
operators
} else {
OperatorSet(operators)
}
}
}
data class ResetOperators(val operators: Iterable) : SideEffect() {
constructor(vararg operators: Operator) : this(listOf(*operators))
constructor(operators: Sequence) : this(operators.toOperatorSet())
val operatorSet: OperatorSet by lazy {
if (operators is OperatorSet) {
operators
} else {
OperatorSet(operators)
}
}
}
data class RemoveOperators(val operators: Iterable) : SideEffect() {
constructor(vararg operators: Operator) : this(listOf(*operators))
constructor(operators: Sequence) : this(operators.toOperatorSet())
val operatorSet: OperatorSet by lazy {
if (operators is OperatorSet) {
operators
} else {
OperatorSet(operators)
}
}
}
data class OpenInputChannels(val inputChannels: Map>) : SideEffect() {
constructor(vararg inputChannels: Pair>) : this(listOf(*inputChannels))
constructor(inputChannels: Iterable>>) : this(inputChannels.toMap())
constructor(inputChannels: Sequence>>) : this(inputChannels.toMap())
}
data class ResetInputChannels(val inputChannels: Map>) : SideEffect() {
constructor(vararg inputChannels: Pair>) : this(listOf(*inputChannels))
constructor(inputChannels: Iterable>>) : this(inputChannels.toMap())
constructor(inputChannels: Sequence>>) : this(inputChannels.toMap())
}
data class CloseInputChannels(val names: Iterable) : SideEffect() {
constructor(vararg names: String) : this(listOf(*names))
constructor(names: Sequence) : this(names.toList())
}
data class OpenOutputChannels(val outputChannels: Map>) : SideEffect() {
constructor(vararg outputChannels: Pair>) : this(listOf(*outputChannels))
constructor(outputChannels: Iterable>>) : this(outputChannels.toMap())
constructor(outputChannels: Sequence>>) : this(outputChannels.toMap())
}
data class ResetOutputChannels(val outputChannels: Map>) : SideEffect() {
constructor(vararg outputChannels: Pair>) : this(listOf(*outputChannels))
constructor(outputChannels: Iterable>>) : this(outputChannels.toMap())
constructor(outputChannels: Sequence>>) : this(outputChannels.toMap())
}
data class CloseOutputChannels(val names: Iterable) : SideEffect() {
constructor(vararg names: String) : this(listOf(*names))
constructor(names: Sequence) : this(names.toList())
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy