MutableTheory

interface MutableTheory : Theory

A Theory that mutates itself in place: assertA/assertZ/retract/abolish (and their plus shorthands) change and return this, instead of building a fresh Theory. This is cheaper than the persistent-data- structure behaviour of a plain Theory when clauses are asserted/retracted very frequently — e.g. to back a Prolog dynamic knowledge base updated on (almost) every resolution step — at the cost of the usual aliasing caveat: every reference to a MutableTheory observes every mutation performed through any other reference.

As with Theory, a MutableTheory can be backed by an indexed or a listed data structure (see indexedOf/listedOf); Theory.toMutableTheory and Theory.toImmutableTheory convert between the two flavours, copying the underlying clauses only when actually needed.

See also

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
abstract val clauses: Iterable<Clause>

All Clauses in this theory

Link copied to clipboard

Only clauses that are Directives

Link copied to clipboard
abstract val isEmpty: Boolean

Whether this Theory is empty or not

Link copied to clipboard
open override val isMutable: Boolean

Whether this Theory supports in-place mutation; true for MutableTheory, false otherwise.

Link copied to clipboard
abstract val isNonEmpty: Boolean

Whether this Theory is full or not

Link copied to clipboard
open val rules: Iterable<Rule>

Only clauses that are Rules

Link copied to clipboard
abstract val size: Long

The amount of clauses in this Theory

Link copied to clipboard
abstract val tags: Map<String, Any>
Link copied to clipboard
abstract val unificator: Unificator

Functions

Link copied to clipboard
abstract override fun abolish(indicator: Indicator): MutableTheory

Removes from this theory all the clauses whose head has the given indicator as functor/arity, mirroring ISO Prolog's abolish/1.

Link copied to clipboard
abstract override fun assertA(clause: Clause): MutableTheory

Returns a Theory with the given clause inserted before all other clauses of this one.

open override fun assertA(struct: Struct): MutableTheory

Returns a Theory with the Fact built from struct inserted before all other clauses of this one

abstract override fun assertA(clauses: Iterable<Clause>): MutableTheory
abstract override fun assertA(clauses: Sequence<Clause>): MutableTheory

Returns a Theory with the given clauses inserted, in order, before all other clauses of this one.

Link copied to clipboard
abstract override fun assertZ(clause: Clause): MutableTheory

Returns a Theory with the given clause inserted after all other clauses of this one.

open override fun assertZ(struct: Struct): MutableTheory

Returns a Theory with the Fact built from struct inserted after all other clauses of this one

abstract override fun assertZ(clauses: Iterable<Clause>): MutableTheory
abstract override fun assertZ(clauses: Sequence<Clause>): MutableTheory

Returns a Theory with the given clauses inserted, in order, after all other clauses of this one.

Link copied to clipboard
abstract override fun clone(): MutableTheory

Returns a copy of this Theory; for an immutable theory this may return this unchanged.

Link copied to clipboard
abstract operator fun contains(clause: Clause): Boolean

Checks if given clause is contained in this theory

abstract operator fun contains(indicator: Indicator): Boolean

Checks if clauses exist in this theory having the specified indicator as head.

abstract operator fun contains(head: Struct): Boolean

Checks if given clause is present in this theory

Link copied to clipboard
open fun containsTag(name: String): Boolean
Link copied to clipboard
abstract fun equals(other: Theory, useVarCompleteName: Boolean): Boolean

Checks whether this theory and other contain the same clauses, in the same order. If useVarCompleteName is true, variables are compared also by their (possibly generated) complete name, rather than only by their position within each clause.

Link copied to clipboard
abstract operator fun get(clause: Clause): Sequence<Clause>

Retrieves the Sequence of clauses in this theory that could unify against the given clause

abstract operator fun get(indicator: Indicator): Sequence<Rule>

Retrieves all the Rules in this theory having the specified indicator as head.

abstract operator fun get(head: Struct): Sequence<Rule>

Retrieves the Sequence of Rules in this theory whose head could unify against the given head

Link copied to clipboard
open fun <T : Any> getTag(name: String): T?
Link copied to clipboard
abstract operator fun iterator(): Iterator<Clause>
Link copied to clipboard
open operator override fun plus(clause: Clause): MutableTheory

Adds the given clause to this Theory; equivalent to assertZ.

abstract operator override fun plus(theory: Theory): MutableTheory

Adds all the clauses of the given theory after all the clauses of this one, returning the resulting Theory (as a new instance, unless is emptyTheory.isEmpty).

Link copied to clipboard
abstract override fun replaceTags(tags: Map<String, Any>): MutableTheory
Link copied to clipboard
abstract override fun retract(clause: Clause): RetractResult<MutableTheory>

Tries to delete the first clause in this theory unifying against the given clause, returning a RetractResult.Success wrapping the resulting Theory and the removed clause, or a RetractResult.Failure wrapping this same theory if no clause matched.

open override fun retract(head: Struct): RetractResult<MutableTheory>

Tries to delete a clause whose head unifies against the given head; equivalent to retract(Rule.of(head, _))

abstract override fun retract(clauses: Iterable<Clause>): RetractResult<MutableTheory>
abstract override fun retract(clauses: Sequence<Clause>): RetractResult<MutableTheory>

Tries to delete, from this theory, one clause unifying against each of the given clauses patterns.

Link copied to clipboard
abstract override fun retractAll(clause: Clause): RetractResult<MutableTheory>

Tries to delete all the clauses in this theory unifying against the given clause

open override fun retractAll(head: Struct): RetractResult<MutableTheory>

Tries to delete all the clauses whose head unifies against the given head; equivalent to retractAll(Rule.of(head, _))

Link copied to clipboard
abstract override fun setUnificator(unificator: Unificator): MutableTheory

Returns a Theory with the same clauses as this one, but using the given unificator to match them.

Link copied to clipboard
abstract fun toImmutableTheory(): Theory

Returns an immutable Theory with the same clauses (and Unificator) as this one; this, if it already is one.

Link copied to clipboard
open override fun toMutableTheory(): MutableTheory

Returns a MutableTheory with the same clauses (and Unificator) as this one; this, if it already is one.

Link copied to clipboard
abstract fun toString(asPrologText: Boolean): String

An enhanced toString that prints the theory in a Prolog program format, if asPrologText is true