MutableTheory
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
Properties
Whether this Theory supports in-place mutation; true for MutableTheory, false otherwise.
Whether this Theory is full or not
Functions
Removes from this theory all the clauses whose head has the given indicator as functor/arity, mirroring ISO Prolog's abolish/1.
Returns a copy of this Theory; for an immutable theory this may return this unchanged.
Checks if given clause is contained in this theory
Checks if clauses exist in this theory having the specified indicator as head.
Checks if given clause is present in this theory
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.
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).
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.
Tries to delete a clause whose head unifies against the given head; equivalent to retract(Rule.of(head, _))
Tries to delete, from this theory, one clause unifying against each of the given clauses patterns.
Returns a Theory with the same clauses as this one, but using the given unificator to match them.
Returns an immutable Theory with the same clauses (and Unificator) as this one; this, if it already is one.
Returns a MutableTheory with the same clauses (and Unificator) as this one; this, if it already is one.
An enhanced toString that prints the theory in a Prolog program format, if asPrologText is true