Unifier

sealed interface Unifier : Substitution

A type for successful Substitutions (a.k.a. unifiers) actually assigning Vars to Terms

Properties

Link copied to clipboard
abstract val entries: Set<Map.Entry<Var, Term>>
Link copied to clipboard
abstract val isFailed: Boolean

Whether this Substitution is a failed one

Link copied to clipboard
abstract val isSuccess: Boolean

Whether this Substitution is a successful one (i.e., a Unifier)

Link copied to clipboard
abstract val keys: Set<Var>
Link copied to clipboard
expect abstract val size: Int
Link copied to clipboard
abstract val tags: Map<String, Any>
Link copied to clipboard
abstract val values: Collection<Term>

Functions

Link copied to clipboard
abstract override fun applyTo(term: Term): Term

Applies this Substitution to the given Term, returning null if it is Substitution.Fail

Link copied to clipboard
open fun <U : Substitution> as(): U?
Link copied to clipboard

Casts the current Substitution to Fail, if possible, or returns null otherwise

Link copied to clipboard
open override fun asUnifier(): Substitution.Unifier

Casts the current Substitution to Unifier, if possible, or returns null otherwise

Link copied to clipboard

Conversion from a raw Map<Var, Term> to the Substitution.Unifier type

Link copied to clipboard
open fun <U : Substitution> castTo(): U
Link copied to clipboard

Casts the current Substitution to Fail, if possible

Link copied to clipboard

Casts the current Substitution to Unifier, if possible

Link copied to clipboard
abstract fun containsKey(key: Var): Boolean
Link copied to clipboard
open fun containsTag(name: String): Boolean
Link copied to clipboard
abstract fun containsValue(value: Term): Boolean
Link copied to clipboard
abstract override fun filter(predicate: (Map.Entry<Var, Term>) -> Boolean): Substitution.Unifier
abstract override fun filter(predicate: (key: Var, value: Term) -> Boolean): Substitution.Unifier

Returns a new substitution containing all key-value pairs matching the given predicate.

abstract override fun filter(variables: Collection<Var>): Substitution.Unifier

Returns a new substitution containing all key-value pairs whose key is in variables.

Link copied to clipboard
abstract operator fun get(key: Var): Term?
Link copied to clipboard
open fun getByName(name: String): Term?

Retrieves the Term bound to the (first) Var whose Var.name equals name, or null if none is found.

Link copied to clipboard
abstract fun getOriginal(variable: Var): Var?

Retrieves the original variable name of the provided variable, if any, or null otherwise

Link copied to clipboard
open fun <T : Any> getTag(name: String): T?
Link copied to clipboard
expect abstract fun isEmpty(): Boolean
Link copied to clipboard
abstract operator override fun minus(other: Substitution): Substitution.Unifier

Returns a new substitution containing all entries of the original substitution except those entries which variable keys are contained in the given other substitution.

abstract operator override fun minus(variable: Var): Substitution.Unifier

Returns a new substitution without the entry (if any) for variable.

abstract operator override fun minus(keys: Iterable<Var>): Substitution.Unifier

Returns a new substitution containing all entries of the original substitution except those entries which variable keys are contained in the given keys iterable.

abstract override fun minus(variable: Var, vararg otherVariables: Var): Substitution.Unifier

Returns a new substitution without the entries (if any) for variable and otherVariables.

Link copied to clipboard
abstract operator fun plus(other: Substitution): Substitution
abstract fun plus(other: Substitution, tagsMerger: TagsOperator): Substitution

Creates a new Substitution that is the composition (a.k.a. union) of this and other. The composition is not guaranteed to be a Substitution.Unifier, even if both arguments are. In fact, the composition algorithm performs the following checks:

Link copied to clipboard
abstract override fun replaceTags(tags: Map<String, Any>): Substitution.Unifier
Link copied to clipboard
open fun <T> whenIs(unifier: (Substitution.Unifier) -> T? = null, fail: (Substitution.Fail) -> T? = null, otherwise: (Substitution) -> T = { throw IllegalStateException("Cannot handle solution $it") }): T

Dispatches on the concrete type of this Substitution, invoking unifier if it is a Unifier, fail if it is a Fail, or otherwise if the relevant callback was not provided (null).