Tuple

interface Tuple : Recursive

A Recursive structure with functor , and arity 2, i.e. the classic Prolog conjunction (A, B). Tuples of more than two terms are represented by right-nesting: (A, B, C) is [left]=A, [right]=(B, C). This is the same functor Prolog uses for clause bodies with multiple goals — that is why Clause.body and Rule.of fold multi-goal bodies into a Tuple under the hood.

Since a two-argument Struct with functor , is structurally identical to a Tuple, Struct.of and wrapIfNeeded automatically return a Tuple whenever that shape arises; there is normally no need to distinguish a plain , /2 Struct from a Tuple by hand.

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
abstract val args: List<Term>

List of arguments of this Struct.

Link copied to clipboard

Sequence of arguments of this Struct.

Link copied to clipboard
open override val arity: Int

The total amount of arguments of this Struct. This is equal to the length of args.

Link copied to clipboard
open override val functor: String

The functor of this Struct.

Link copied to clipboard

The indicator corresponding to this Struct, i.e. functor/arity.

Link copied to clipboard
open override val isAtom: Boolean

Checks whether the current term is an atom. This method is guaranteed to return true if and only if the current term is an instance of Atom.

Link copied to clipboard
open override val isBlock: Boolean

Checks whether the current term is a logic block. This method is guaranteed to return true if and only if the current term is an instance of Block.

Link copied to clipboard
open override val isClause: Boolean

Checks whether the current term is a clause, i.e., either a rule or a directive. This method is guaranteed to return true if and only if the current term is an instance of Clause.

Link copied to clipboard
open override val isCons: Boolean

Checks whether the current term is a cons. This method is guaranteed to return true if and only if the current term is an instance of Cons.

Link copied to clipboard

Checks whether the current term is a constant, i.e., either an atom or a number. This method is guaranteed to return true if and only if the current term is an instance of Constant.

Link copied to clipboard
open override val isDirective: Boolean

Checks whether the current term is a directive. This method is guaranteed to return true if and only if the current term is an instance of Directive.

Link copied to clipboard
open override val isEmptyBlock: Boolean

Checks whether the current term is an empty logic block. This method is guaranteed to return true if and only if the current term is an instance of EmptyBlock.

Link copied to clipboard
open override val isEmptyList: Boolean

Checks whether the current term is an empty logic list. This method is guaranteed to return true if and only if the current term is an instance of EmptyList.

Link copied to clipboard
open override val isFact: Boolean

Checks whether the current term is a fact. This method is guaranteed to return true if and only if the current term is an instance of Fact.

Link copied to clipboard
open override val isFail: Boolean

Checks whether the current term is the either the fail atom or the false atom. This method is guaranteed to return true if and only if the current term is an instance of Truth and its Truth.value is "fail" or "false".

Link copied to clipboard

Returns true if and only if functor matches Struct.WELL_FORMED_FUNCTOR_PATTERN.

Link copied to clipboard
open val isGround: Boolean

Checks whether the current object is ground. An object is ground if and only if it does not contain any variable. This method is guaranteed to return true if and only if the variables property of the current object refers to an empty sequence.

Link copied to clipboard
open override val isIndicator: Boolean

Checks whether the current term is an indicator. This method is guaranteed to return true if and only if the current term is an instance of Indicator.

Link copied to clipboard
open val isInteger: Boolean

Checks whether the current term is an integer. This method is guaranteed to return true if and only if the current term is an instance of Integer.

Link copied to clipboard
open override val isList: Boolean

Checks whether the current term is a (logic) list, i.e., either an empty list or a Cons. This method is guaranteed to return true if and only if the current term is an instance of List.

Link copied to clipboard
open val isNumber: Boolean

Checks whether the current term is a number, i.e., either an integer or a real number. This method is guaranteed to return true if and only if the current term is an instance of Numeric.

Link copied to clipboard
open val isReal: Boolean

Checks whether the current term is a real number. This method is guaranteed to return true if and only if the current term is an instance of Real.

Link copied to clipboard
open override val isRecursive: Boolean

Checks whether the current term is a recursive structure, i.e., a list, a tuple, or a block. This method is guaranteed to return true if and only if the current term is an instance of Recursive.

Link copied to clipboard
open override val isRule: Boolean

Checks whether the current term is a rule, or a fact. This method is guaranteed to return true if and only if the current term is an instance of Rule.

Link copied to clipboard
open override val isStruct: Boolean

Checks whether the current term is a structure, i.e., either a compound term or an atom. This method is guaranteed to return true if and only if the current term is an instance of Struct.

Link copied to clipboard
open override val isTrue: Boolean

Checks whether the current term is the true atom. This method is guaranteed to return true if and only if the current term is an instance of Truth and its Truth.value is "true".

Link copied to clipboard
open val isTruth: Boolean

Checks whether the current term is a truth value. This method is guaranteed to return true if and only if the current term is an instance of Truth.

Link copied to clipboard
open override val isTuple: Boolean

Checks whether the current term is a logic tuple, i.e., a right-recursive conjunction of 2 or more terms. This method is guaranteed to return true if and only if the current term is an instance of Tuple.

Link copied to clipboard
open val isVar: Boolean

Checks whether the current term is a variable. This method is guaranteed to return true if and only if the current term is an instance of Var.

Link copied to clipboard
abstract val items: Iterable<Term>

Alias for unfoldedSequence, exposed as an Iterable.

Link copied to clipboard
abstract val left: Term

The first (leftmost) element of this Tuple.

Link copied to clipboard
abstract val right: Term

The rest of this Tuple: either the last element, or a nested Tuple holding the remaining elements.

Link copied to clipboard
abstract val size: Int

The number of elements in this structure, once unfolded.

Link copied to clipboard
abstract val tags: Map<String, Any>
Link copied to clipboard
abstract val unfoldedArray: Array<Term>

The elements of this structure, unfolded eagerly into an Array.

Link copied to clipboard
abstract val unfoldedList: List<Term>

The elements of this structure, unfolded eagerly into a List.

Link copied to clipboard

The elements of this structure, unfolded lazily, in order. Same as unfold.

Link copied to clipboard
open override val variables: Sequence<Var>

The sequence of Variables directly or indirectly contained in the current object. Variables are lazily returned in a non-deterministic order. Notice that no occurrence-check is performed. Thus, if a Term contains the same Variable twice or more times, then the variables sequence may contain as many occurrences of that Variable

Functions

Link copied to clipboard
abstract fun <T> accept(visitor: TermVisitor<T>): T

Lets the provided TermVisitor navigate the current term and build an object of type T. Such an object is then returned as a result by this method.

Link copied to clipboard
abstract fun addFirst(argument: Term): Struct

Creates a novel Struct which is a copy of the current one, expect that is has one more argument. The novel argument is appended at the beginning of the new Struct's arguments list.

Link copied to clipboard
abstract fun addLast(argument: Term): Struct

Creates a novel Struct which is a copy of the current one, expect that is has one more argument. The novel argument is appended at the end of the new Struct's arguments list.

Link copied to clipboard
open fun append(argument: Term): Struct

An alias for addLast.

Link copied to clipboard
abstract fun apply(substitution: Substitution): Term

Applies a Substitution to the current object, producing a new instance of T which differs from the current object because variables are replaced by their values, according to the binding carried by substitution.

open fun apply(substitution: Substitution, vararg substitutions: Substitution): Term

Applies one or more Substitutions to the current object, producing a new instance of T which differs from the current one because variables are replaced by their values, according to the binding carried by the provided substitutions.

Link copied to clipboard
open override fun <T : Term> as(): T?

Helper method aimed at down-casting Terms using a fluent style

Link copied to clipboard
open fun asAtom(): Atom?

Casts the current Term to Atom, if possible, or returns null otherwise

Link copied to clipboard
open fun asBlock(): Block?

Casts the current Term to Block, if possible, or returns null otherwise

Link copied to clipboard
open fun asClause(): Clause?

Casts the current Term to Clause, if possible, or returns null otherwise

Link copied to clipboard
open fun asCons(): Cons?

Casts the current Term to Cons, if possible, or returns null otherwise

Link copied to clipboard
open fun asConstant(): Constant?

Casts the current Term to Constant, if possible, or returns null otherwise

Link copied to clipboard
open fun asDirective(): Directive?

Casts the current Term to Directive, if possible, or returns null otherwise

Link copied to clipboard

Casts the current Term to EmptyBlock, if possible, or returns null otherwise

Link copied to clipboard
open fun asEmptyList(): EmptyList?

Casts the current Term to EmptyList, if possible, or returns null otherwise

Link copied to clipboard
open fun asFact(): Fact?

Casts the current Term to Fact, if possible, or returns null otherwise

Link copied to clipboard
open fun asIndicator(): Indicator?

Casts the current Term to Indicator, if possible, or returns null otherwise

Link copied to clipboard
open fun asInteger(): Integer?

Casts the current Term to Integer, if possible, or returns null otherwise

Link copied to clipboard
open fun asList(): List?

Casts the current Term to List, if possible, or returns null otherwise

Link copied to clipboard
open fun asNumeric(): Numeric?

Casts the current Term to Numeric, if possible, or returns null otherwise

Link copied to clipboard
open fun asReal(): Real?

Casts the current Term to Real, if possible, or returns null otherwise

Link copied to clipboard
open override fun asRecursive(): Recursive

Casts the current Term to Recursive, if possible, or returns null otherwise

Link copied to clipboard
open fun asRule(): Rule?

Casts the current Term to Rule, if possible, or returns null otherwise

Link copied to clipboard
open override fun asStruct(): Struct

Casts the current Term to Struct, if possible, or returns null otherwise

Link copied to clipboard
open fun asTerm(): Term

Casts the current Term to Term

Link copied to clipboard
open fun asTruth(): Truth?

Casts the current Term to Truth, if possible, or returns null otherwise

Link copied to clipboard
open override fun asTuple(): Tuple

Casts the current Term to Tuple, if possible, or returns null otherwise

Link copied to clipboard
open fun asVar(): Var?

Casts the current Term to Var, if possible, or returns null otherwise

Link copied to clipboard
open override fun <T : Term> castTo(): T

Helper method aimed at down-casting Terms using a fluent style

Link copied to clipboard
open fun castToAtom(): Atom

Casts the current Term to Atom, if possible

Link copied to clipboard
open fun castToBlock(): Block

Casts the current Term to Block, if possible

Link copied to clipboard
open fun castToClause(): Clause

Casts the current Term to Clause, if possible

Link copied to clipboard
open fun castToCons(): Cons

Casts the current Term to Cons, if possible

Link copied to clipboard

Casts the current Term to Constant, if possible

Link copied to clipboard

Casts the current Term to Directive, if possible

Link copied to clipboard

Casts the current Term to EmptyBlock, if possible

Link copied to clipboard

Casts the current Term to EmptyList, if possible

Link copied to clipboard
open fun castToFact(): Fact

Casts the current Term to Fact, if possible

Link copied to clipboard

Casts the current Term to Indicator, if possible

Link copied to clipboard

Casts the current Term to Integer, if possible

Link copied to clipboard
open fun castToList(): List

Casts the current Term to List, if possible

Link copied to clipboard

Casts the current Term to Numeric, if possible

Link copied to clipboard
open fun castToReal(): Real

Casts the current Term to Real, if possible

Link copied to clipboard

Casts the current Term to Recursive, if possible

Link copied to clipboard
open fun castToRule(): Rule

Casts the current Term to Rule, if possible

Link copied to clipboard
open fun castToStruct(): Struct

Casts the current Term to Struct, if possible

Link copied to clipboard
open fun castToTerm(): Term

Casts the current Term to Term

Link copied to clipboard
open fun castToTruth(): Truth

Casts the current Term to Truth, if possible

Link copied to clipboard
open fun castToTuple(): Tuple

Casts the current Term to Tuple, if possible

Link copied to clipboard
open fun castToVar(): Var

Casts the current Term to Var, if possible

Link copied to clipboard
open operator override fun compareTo(other: Term): Int

Compares this term to the provided one, returning a positive integer if this term precedes other, a negative integer if other precedes this term, or 0 otherwise

Link copied to clipboard
open fun containsTag(name: String): Boolean
Link copied to clipboard
abstract operator override fun equals(other: Any?): Boolean

abstract fun equals(other: Term, useVarCompleteName: Boolean): Boolean

Checks whether another term is equals to the current one or not, by explicitly letting the client decide whether to rely or not on Varriables complete names for checking equality among two Variables. If useVarCompleteName is true, Variables are compared through their Var.completeName property. Otherwise, they are compared through their Var.name property. Other sorts of terms are compared as Term.equals(Any?).

Link copied to clipboard
abstract override fun freshCopy(): Tuple

Returns a fresh copy of this object, that is, an instance of T which is equal to the current one in any aspect, except for variables directly or indirectly contained into this object, which are refreshed. This means the method could return this object itself, if no variable is present, or a new object with freshly generated variables.

abstract override fun freshCopy(scope: Scope): Tuple

Returns a fresh copy of this object, similarly to freshCopy(), possibly reusing variables from the provided scope, if any

Link copied to clipboard
open operator fun get(substitution: Substitution, vararg substitutions: Substitution): Term

This is an alias for apply aimed at supporting a square-brackets syntax for substitutions applications in Kotlin programs. It lets programmers write object[substitution] instead of object.apply(substitution). It applies one or more Substitutions to the current object, producing a new Term which differs from the current one because variables are replaced by their values, according to the binding carried by the provided substitutions.

open operator fun get(index: Int): Term

Alias for getArgAt. In Kotlin, this method enables the syntax struct[index].

Link copied to clipboard
open fun getArgAt(index: Int): Term

Gets the index-th argument if this Struct.

Link copied to clipboard
open fun <T : Any> getTag(name: String): T?
Link copied to clipboard
abstract override fun hashCode(): Int
Link copied to clipboard
abstract fun insertAt(index: Int, argument: Term): Struct

Creates a novel Struct which is a copy of the current one, expect that is has one more argument. The novel argument is inserted into the new Struct's arguments list, at index index, wheres subsequent arguments indexes are shifted by 1.

Link copied to clipboard
abstract fun replaceTags(tags: Map<String, Any>): Term
Link copied to clipboard
abstract fun setArgs(args: Iterable<Term>): Struct
abstract fun setArgs(args: Sequence<Term>): Struct

abstract fun setArgs(vararg args: Term): Struct

Creates a novel Struct which is a copy of the current one, except that its args are replaced by args.

Link copied to clipboard
abstract fun setFunctor(functor: String): Struct

Creates a novel Struct which is a copy of the current one, expect that is has a different functor.

Link copied to clipboard
abstract infix fun structurallyEquals(other: Term): Boolean

Checks whether another term is structurally equals to the current one or not. Structural equivalence is a looser type of equivalence (w.r.t. term equivalence) where:

Link copied to clipboard
open override fun toArray(): Array<Term>

Eagerly unfolds this structure's elements into an Array. Same as unfoldedArray.

Link copied to clipboard
open override fun toList(): List<Term>

Eagerly unfolds this structure's elements into a List. Same as unfoldedList.

Link copied to clipboard
open override fun toSequence(): Sequence<Term>

Lazily unfolds this structure's elements into a Sequence. Same as unfoldedSequence.

Link copied to clipboard
abstract override fun toString(): String
Link copied to clipboard
abstract fun unfold(): Sequence<Term>

Lazily unfolds this structure's elements. Same as unfoldedSequence.