interface Term: Comparable<Term>, Any
Fields
Name | Description |
---|---|
abstract variables: Sequence<Var>
|
The sequence of Variables directly or indirectly contained in the current term. 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 |
open isVar: Boolean
|
Checks whether the current term is a variable.
This method is guaranteed to return |
open isGround: Boolean
|
Checks whether the current term is ground.
A term is ground is ground if and only if it does not contain any variable.
This method is guaranteed to return |
open 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 |
open isTruth: Boolean
|
Checks whether the current term is a truth value.
This method is guaranteed to return |
open 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 |
open isAtom: Boolean
|
Checks whether the current term is an atom.
This method is guaranteed to return |
open isConstant: Boolean
|
Checks whether the current term is a constant, i.e., either an atom or a number.
This method is guaranteed to return |
open 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 |
open isInteger: Boolean
|
Checks whether the current term is an integer.
This method is guaranteed to return |
open isReal: Boolean
|
Checks whether the current term is a real number.
This method is guaranteed to return |
open 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 |
open 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 |
open isBlock: Boolean
|
Checks whether the current term is a logic block.
This method is guaranteed to return |
open isEmptyBlock: Boolean
|
Checks whether the current term is an empty logic block.
This method is guaranteed to return |
open isClause: Boolean
|
Checks whether the current term is a clause, i.e., either a rule or a directive.
This method is guaranteed to return |
open isRule: Boolean
|
Checks whether the current term is a rule, or a fact.
This method is guaranteed to return |
open isFact: Boolean
|
Checks whether the current term is a fact.
This method is guaranteed to return |
open isDirective: Boolean
|
Checks whether the current term is a directive.
This method is guaranteed to return |
open isCons: Boolean
|
Checks whether the current term is a cons.
This method is guaranteed to return |
open isEmptyList: Boolean
|
Checks whether the current term is an empty logic list.
This method is guaranteed to return |
open isTrue: Boolean
|
Checks whether the current term is the |
open isFail: Boolean
|
Checks whether the current term is the either the |
open isIndicator: Boolean
|
Checks whether the current term is an indicator.
This method is guaranteed to return |
Methods
as
open fun <T : Term> as(): T?
Helper method aimed at down-casting Terms using a fluent style
ReturnValue
Name | Description |
---|---|
T?
|
the current term, cast'd into type T, or |
castTo
open fun <T : Term> castTo(): T
Helper method aimed at down-casting Terms using a fluent style
ReturnValue
Name | Description |
---|---|
T
|
the current term, cast'd into type T |
compareTo
open 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
Parameters
Name | Description |
---|---|
other: Term
|
is the term to be compared against this term |
ReturnValue
Name | Description |
---|---|
Int
|
an Int indicating whether this term precedes other or not |
equals
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?)
.
For example, if useVarCompleteName is true
the following comparison should fail:
Var.of("X") == Var.of("X")
otherwise, it should succeed.
Parameters
ReturnValue
Name | Description |
---|---|
Boolean
|
|
equals
abstract fun equals(other: Any?): Boolean
Parameters
Name | Description |
---|---|
other: Any?
|
ReturnValue
Name | Description |
---|---|
Boolean
|
structurallyEquals
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:
- numbers are compared by value, e.g.
1
is structurally equal to1.0
- variables are always considered equal, e.g.
f(X)
is structurally equal tof(_)
ReturnValue
Name | Description |
---|---|
Boolean
|
|
freshCopy
abstract fun freshCopy(): Term
Returns a fresh copy of this Term, that is, an instance of Term which is equal to the current one in any aspect, except variables directly or indirectly contained into this Term, which are refreshed. This means that it could return itself, if no variable is present (ground term), or a new Term with freshly generated variables.
Variables are refreshed consistently, meaning that, if more variables exists within this Term having the same name, all fresh copies of such variables will have the same complete name.
Example: "f(X, g(X))".freshCopy() returns something like "f(X_1, g(X_1))" instead of "f(X_1, g(X_2))"
Notice that, if the current term is ground, the same object may be returned as a result by this method.
ReturnValue
Name | Description |
---|---|
Term
|
a fresh copy of the current term which is different because variables are consistently renamed |
freshCopy
abstract fun freshCopy(scope: Scope): Term
Returns a fresh copy of this Term, similarly to freshCopy
, possibly reusing variables from the provided scope,
if any
Parameters
Name | Description |
---|---|
scope: Scope
|
the Scope containing variables to be used in copying |
ReturnValue
Name | Description |
---|---|
Term
|
a fresh copy of the current term which is different because variables are consistently renamed |
apply
abstract fun apply(substitution: Substitution): Term
Applies a Substitution to the current term, producing a new Term which differs from the current one because variables are replaced by their values, according to the binding carried by substitution.
Notice that, if the current term is ground, or the provided substitution is empty, the same object may be returned as a result by this method.
Parameters
Name | Description |
---|---|
substitution: Substitution
|
is the Substitution to be applied to the current term |
apply
open fun apply(substitution: Substitution, vararg substitutions: Substitution): Term
Applies one or more Substitutions to the current term, 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.
This method behaves like apply, assuming that the provided substitutions have been merged by means of Substitution.of.
Parameters
Name | Description |
---|---|
substitution: Substitution
|
is the first Substitution to be applied to the current term |
vararg substitutions: Substitution
|
is the vararg argument representing the 2nd, 3rd, etc., Substitutions to be applied |
get
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 term[substitution]
instead of term.apply(substitution)
.
It applies one or more Substitutions to the current term, 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.
This method behaves like apply, assuming that the provided substitutions have been merged by means of Substitution.of.
Parameters
Name | Description |
---|---|
substitution: Substitution
|
is the first Substitution to be applied to the current term |
vararg substitutions: Substitution
|
is the vararg argument representing the 2nd, 3rd, etc., Substitutions to be applied |
accept
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.
See also: https://en.wikipedia.org/wiki/Visitor_pattern for more information concerning the GoF's Visitor pattern.
Parameters
Name | Description |
---|---|
visitor: TermVisitor<T>
|
is a TermVisitor, i.e., an object aimed at navigating the current term |
ReturnValue
Name | Description |
---|---|
T
|
an object of type T, produced by visitor through its visit |
castToAtom
open fun castToAtom(): Atom
castToClause
open fun castToClause(): Clause
castToCons
open fun castToCons(): Cons
castToConstant
open fun castToConstant(): Constant
castToDirective
open fun castToDirective(): Directive
castToEmptyList
open fun castToEmptyList(): EmptyList
castToEmptyBlock
open fun castToEmptyBlock(): EmptyBlock
Casts the current Term to EmptyBlock, if possible
ReturnValue
Name | Description |
---|---|
EmptyBlock
|
the current Term, casted to EmptyBlock |
castToFact
open fun castToFact(): Fact
castToIndicator
open fun castToIndicator(): Indicator
castToInteger
open fun castToInteger(): Integer
castToList
open fun castToList(): List
castToNumeric
open fun castToNumeric(): Numeric
castToReal
open fun castToReal(): Real
castToRule
open fun castToRule(): Rule
castToBlock
open fun castToBlock(): Block
castToStruct
open fun castToStruct(): Struct
castToRecursive
open fun castToRecursive(): Recursive
castToTerm
open fun castToTerm(): Term
castToTruth
open fun castToTruth(): Truth
castToTuple
open fun castToTuple(): Tuple
castToVar
open fun castToVar(): Var
asAtom
open fun asAtom(): Atom?
asClause
open fun asClause(): Clause?
asCons
open fun asCons(): Cons?
asConstant
open fun asConstant(): Constant?
asDirective
open fun asDirective(): Directive?
asEmptyList
open fun asEmptyList(): EmptyList?
asEmptyBlock
open fun asEmptyBlock(): EmptyBlock?
Casts the current Term to EmptyBlock, if possible, or returns null
otherwise
ReturnValue
Name | Description |
---|---|
EmptyBlock?
|
the current Term, casted to EmptyBlock, or |
asFact
open fun asFact(): Fact?
asIndicator
open fun asIndicator(): Indicator?
asInteger
open fun asInteger(): Integer?
asList
open fun asList(): List?
asNumeric
open fun asNumeric(): Numeric?
asReal
open fun asReal(): Real?
asRule
open fun asRule(): Rule?
asBlock
open fun asBlock(): Block?
asStruct
open fun asStruct(): Struct?
asRecursive
open fun asRecursive(): Recursive?
asTerm
open fun asTerm(): Term
asTruth
open fun asTruth(): Truth?
asTuple
open fun asTuple(): Tuple?
asVar
open fun asVar(): Var?
hashCode
abstract fun hashCode(): Int
ReturnValue
Name | Description |
---|---|
Int
|
toString
abstract fun toString(): String
ReturnValue
Name | Description |
---|---|
String
|
Extensions
toClause
fun Term.toClause(source: Any?, line: Int, column: Int): Clause
Receiver
Name | Description |
---|---|
Term
|
Parameters
Name | Description |
---|---|
source: Any?
|
|
line: Int
|
|
column: Int
|
ReturnValue
Name | Description |
---|---|
Clause
|
unfoldGoals
fun Term.unfoldGoals(): Sequence
Receiver
Name | Description |
---|---|
Term
|
ReturnValue
Name | Description |
---|---|
Sequence
|
toGoals
fun Term.toGoals(): Cursor
Receiver
Name | Description |
---|---|
Term
|
ReturnValue
Name | Description |
---|---|
Cursor
|
isWellFormed
fun Term.isWellFormed(): Boolean
Check whether the receiver term is a well-formed predication
Receiver
Name | Description |
---|---|
Term
|
ReturnValue
Name | Description |
---|---|
Boolean
|
prepareForExecutionAsGoal
fun Term.prepareForExecutionAsGoal(): Struct
Prepares the receiver Goal for execution
For example, the goal A
is transformed, after preparation for execution, as the Term: call(A)
Receiver
Name | Description |
---|---|
Term
|
ReturnValue
Name | Description |
---|---|
Struct
|
evalAsExpression
fun Term.evalAsExpression(request: Request<*>, index: Int?): Term
Receiver
Name | Description |
---|---|
Term
|
Parameters
Name | Description |
---|---|
request: Request<*>
|
|
index: Int?
|
ReturnValue
Name | Description |
---|---|
Term
|
Base type for all logic terms. Terms are immutable tree-like data structures.