Atom

interface Atom: Struct, Constant, Any

Base type for constant, alphanumeric Terms, a.k.a. strings. An Atom is at the same time a String-valued Constant and a 0-argument Struct, whose functor is equal to value.

Fields

Name Description
open arity: Int

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

open 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.

open 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.

open 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.

open 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".

open 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".

open value: String
open args: List<Term>

List of arguments of this Struct.

open 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

Methods

freshCopy

abstract fun freshCopy(): Atom

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
Atom

a fresh copy of the current term which is different because variables are consistently renamed

freshCopy

abstract fun freshCopy(scope: Scope): Atom

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
Atom

a fresh copy of the current term which is different because variables are consistently renamed

asAtom

open fun asAtom(): Atom

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

ReturnValue

Name Description
Atom

the current Term, casted to Atom, or null, if the current term is not an instance of Atom

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<Term>

Receiver

Name Description
Term

ReturnValue

Name Description
Sequence<Term>

toGoals

fun Term.toGoals(): Cursor<Term>

Receiver

Name Description
Term

ReturnValue

Name Description
Cursor<Term>

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

extractSignature

fun Struct.extractSignature(): Signature

Extracts this Struct indicator and converts it to Signature

Receiver

Name Description
Struct

ReturnValue

Name Description
Signature

evalAsExpression

fun Term.evalAsExpression(request: Request<*>, index: Int?): Term

Receiver

Name Description
Term

Parameters

Name Description
request: Request<*>
index: Int?

ReturnValue

Name Description
Term

evalAsArithmeticExpression

fun Term.evalAsArithmeticExpression(request: Request<*>, index: Int?): Numeric

Receiver

Name Description
Term

Parameters

Name Description
request: Request<*>
index: Int?

ReturnValue

Name Description
Numeric

eq

infix fun Term.eq(that: Term): Equation

Creates an equation with this and that terms

Receiver

Name Description
Term

Parameters

Name Description
that: Term

ReturnValue

Name Description
Equation

CompanionObject

Atom

interface Atom: Struct, Constant, Any

Base type for constant, alphanumeric Terms, a.k.a. strings. An Atom is at the same time a String-valued Constant and a 0-argument Struct, whose functor is equal to value.

Fields

Name Description
val ATOM_PATTERN: @JvmField

Methods

escapeValue

fun escapeValue(string: String): String

Parameters

Name Description
string: String

ReturnValue

Name Description
String

escapeValueIfNecessary

fun escapeValueIfNecessary(string: String): String

Parameters

Name Description
string: String

ReturnValue

Name Description
String

of

fun of(value: String): Atom

Parameters

Name Description
value: String

ReturnValue

Name Description
Atom

Extensions

parse

fun Atom.Companion.parse(input: String, operators: OperatorSet): Atom

Receiver

Name Description
Atom.Companion

Parameters

Name Description
input: String
operators: OperatorSet

ReturnValue

Name Description
Atom

parse

fun Atom.Companion.parse(input: String): Atom

Receiver

Name Description
Atom.Companion

Parameters

Name Description
input: String

ReturnValue

Name Description
Atom