Clause

interface Clause: Struct, Any

Fields

Name Description
open functor: String

The functor of this Struct.

abstract head: Struct?
abstract body: Term
abstract isWellFormed: Boolean

Checks whether this Clause is wellFormed

A Clause is said to be "well formed" if:

  • its head isn't a Numeric or a Var
  • its body isn't a Numeric and doesn't contain a Numeric in arguments place, for notable Structs with functors ','/2, ';'/2 and '->'/2
open arity: Int

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

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 true if and only if the current term is an instance of Clause.

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

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

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

abstract bodyItems: Iterable<Term>
abstract bodySize: Int
abstract bodyAsTuple: Tuple?

Methods

freshCopy

abstract fun freshCopy(): Clause

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
Clause

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

freshCopy

abstract fun freshCopy(scope: Scope): Clause

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
Clause

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

asClause

open fun asClause(): Clause

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

ReturnValue

Name Description
Clause

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

getBodyItem

abstract fun getBodyItem(index: Int): Term

Parameters

Name Description
index: Int

ReturnValue

Name Description
Term

setHead

abstract fun setHead(head: Struct): Rule

Parameters

Name Description
head: Struct

ReturnValue

Name Description
Rule

setBody

abstract fun setBody(body: Term): Clause

Parameters

Name Description
body: Term

ReturnValue

Name Description
Clause

setHeadFunctor

abstract fun setHeadFunctor(functor: String): Clause

Parameters

Name Description
functor: String

ReturnValue

Name Description
Clause

setHeadArgs

abstract fun setHeadArgs(vararg arguments: Term): Clause

Parameters

Name Description
vararg arguments: Term

ReturnValue

Name Description
Clause

setHeadArgs

abstract fun setHeadArgs(arguments: Iterable<Term>): Clause

Parameters

Name Description
arguments: Iterable<Term>

ReturnValue

Name Description
Clause

setHeadArgs

abstract fun setHeadArgs(arguments: Sequence<Term>): Clause

Parameters

Name Description
arguments: Sequence<Term>

ReturnValue

Name Description
Clause

insertHeadArg

abstract fun insertHeadArg(index: Int, argument: Term): Clause

Parameters

Name Description
index: Int
argument: Term

ReturnValue

Name Description
Clause

addFirstHeadArg

abstract fun addFirstHeadArg(argument: Term): Clause

Parameters

Name Description
argument: Term

ReturnValue

Name Description
Clause

addLastHeadArg

abstract fun addLastHeadArg(argument: Term): Clause

Parameters

Name Description
argument: Term

ReturnValue

Name Description
Clause

appendHeadArg

abstract fun appendHeadArg(argument: Term): Clause

Parameters

Name Description
argument: Term

ReturnValue

Name Description
Clause

setBodyItems

abstract fun setBodyItems(argument: Term, vararg arguments: Term): Clause

Parameters

Name Description
argument: Term
vararg arguments: Term

ReturnValue

Name Description
Clause

setBodyItems

abstract fun setBodyItems(arguments: Iterable<Term>): Clause

Parameters

Name Description
arguments: Iterable<Term>

ReturnValue

Name Description
Clause

setBodyItems

abstract fun setBodyItems(arguments: Sequence<Term>): Clause

Parameters

Name Description
arguments: Sequence<Term>

ReturnValue

Name Description
Clause

insertBodyItem

abstract fun insertBodyItem(index: Int, argument: Term): Clause

Parameters

Name Description
index: Int
argument: Term

ReturnValue

Name Description
Clause

addFirstBodyItem

abstract fun addFirstBodyItem(argument: Term): Clause

Parameters

Name Description
argument: Term

ReturnValue

Name Description
Clause

addLastBodyItem

abstract fun addLastBodyItem(argument: Term): Clause

Parameters

Name Description
argument: Term

ReturnValue

Name Description
Clause

appendBodyItem

abstract fun appendBodyItem(argument: Term): Clause

Parameters

Name Description
argument: Term

ReturnValue

Name Description
Clause

Extensions

prepareForExecution

fun Clause.prepareForExecution(): Clause

Prepares the receiver Clause for execution, using the provided visitor

For example, the Clause product(A) :- A, A is transformed, after preparation for execution, as the Term: product(A) :- call(A), call(A)

Receiver

Name Description
Clause

ReturnValue

Name Description
Clause

prepareForExecution

fun Clause.prepareForExecution(unifier: Unifier): Clause

Receiver

Name Description
Clause

Parameters

Name Description
unifier: Unifier

ReturnValue

Name Description
Clause

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

Clause

interface Clause: Struct, Any

Fields

Name Description
const FUNCTOR: String
val notableFunctors: /** Contains notable functor in determining if a Clause [isWellFormed] */

Contains notable functor in determining if a Clause isWellFormed

val bodyWellFormedVisitor: TermVisitor<Boolean>

A visitor that checks whether isWellFormed (body constraints part) is respected

Methods

of

fun of(head: Struct?, vararg body: Term): Clause

Parameters

Name Description
head: Struct?
vararg body: Term

ReturnValue

Name Description
Clause

of

fun of(head: Struct?, body: Iterable<Term>): Clause

Parameters

Name Description
head: Struct?
body: Iterable<Term>

ReturnValue

Name Description
Clause

of

fun of(head: Struct?, body: Sequence<Term>): Clause

Parameters

Name Description
head: Struct?
body: Sequence<Term>

ReturnValue

Name Description
Clause

Extensions

parse

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

Receiver

Name Description
Clause.Companion

Parameters

Name Description
input: String
operators: OperatorSet

ReturnValue

Name Description
Clause

parse

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

Receiver

Name Description
Clause.Companion

Parameters

Name Description
input: String

ReturnValue

Name Description
Clause