Fields
Name | Description |
---|---|
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 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 isDirective: Boolean
|
Checks whether the current term is a directive.
This method is guaranteed to return |
open isFact: Boolean
|
Checks whether the current term is a fact.
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 isAtom: Boolean
|
Checks whether the current term is an atom.
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 isCons: Boolean
|
Checks whether the current term is a cons.
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 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 |
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 |
abstract functor: String
|
The functor of this Struct. |
abstract isFunctorWellFormed: Boolean
|
Returns |
open arity: Int
|
The total amount of arguments of this Struct. This is equal to the length of args. |
open indicator: Indicator
|
The indicator corresponding to this Struct, i.e. functor/arity. |
abstract args: List<Term>
|
List of arguments of this Struct. |
open argsSequence: Sequence
|
Sequence of arguments of this Struct. |
Methods
freshCopy
abstract fun freshCopy(): Struct
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 |
---|---|
Struct
|
a fresh copy of the current term which is different because variables are consistently renamed |
freshCopy
abstract fun freshCopy(scope: Scope): Struct
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 |
---|---|
Struct
|
a fresh copy of the current term which is different because variables are consistently renamed |
asStruct
open fun asStruct(): Struct
append
open fun append(argument: Term): Struct
An alias for addLast.
Parameters
Name | Description |
---|---|
argument: Term
|
ReturnValue
Name | Description |
---|---|
Struct
|
addLast
addFirst
insertAt
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.
Parameters
setFunctor
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.
Parameters
Name | Description |
---|---|
functor: String
|
is a String representing the new functor |
getArgAt
open fun getArgAt(index: Int): Term
Gets the index-th argument if this Struct.
Parameters
Name | Description |
---|---|
index: Int
|
is the index the argument which should be retrieved |
setArgs
abstract fun setArgs(vararg args: Term): Struct
Parameters
Name | Description |
---|---|
vararg args: Term
|
ReturnValue
Name | Description |
---|---|
Struct
|
setArgs
abstract fun setArgs(args: Iterable<Term>): Struct
Parameters
Name | Description |
---|---|
args: Iterable<Term>
|
ReturnValue
Name | Description |
---|---|
Struct
|
Extensions
extractSignature
fun Struct.extractSignature(): Signature
Receiver
Name | Description |
---|---|
Struct
|
ReturnValue
Name | Description |
---|---|
Signature
|
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
|
CompanionObject
Struct
Base type for compound Terms, a.k.a. structures. A Struct is characterised by a functor and a given (non-negative) amount of args, namely arity. Each argument can be a Term of any sort.
Fields
Name | Description |
---|---|
val WELL_FORMED_FUNCTOR_PATTERN: /**
* The pattern of a well-formed functor for a [Struct].
* A functor is well-formed if and only if:
* - it starts with a lower-case letter
* - it only contains letters, digits, or underscores
*/
|
The pattern of a well-formed functor for a Struct. A functor is well-formed if and only if:
|
val NON_PRINTABLE_CHARACTER_PATTERN: /**
* The pattern of an ill-formed functor for a [Struct] containing
* - non-printable characters (e.g. `\n`, `\r`, `\t`)
* - other characters which must be escaped (e.g. `"`, `'`, `\`)
*/
|
The pattern of an ill-formed functor for a Struct containing
|
Methods
isWellFormedFunctor
fun isWellFormedFunctor(string: String): Boolean
Checks if a string matches WELL_FORMED_FUNCTOR_PATTERN.
Parameters
Name | Description |
---|---|
string: String
|
the String to be checked |
ReturnValue
Name | Description |
---|---|
Boolean
|
|
enquoteFunctor
fun enquoteFunctor(string: String): String
Wraps the provided string within single quotes, unconditionally.
Parameters
Name | Description |
---|---|
string: String
|
the String to be enquoted |
ReturnValue
Name | Description |
---|---|
String
|
a new String, beginning and ending with |
enquoteFunctorIfNecessary
fun enquoteFunctorIfNecessary(string: String): String
Wraps the provided string within single quotes, but only if it is not well-formed. Well-formed check is performed via the isWellFormedFunctor method.
Parameters
Name | Description |
---|---|
string: String
|
the String to be enquoted |
ReturnValue
Name | Description |
---|---|
String
|
either a new String, beginning and ending with |
functorNeedsEscape
fun functorNeedsEscape(string: String): Boolean
Checks if a string matches NON_PRINTABLE_CHARACTER_PATTERN.
Parameters
Name | Description |
---|---|
string: String
|
the String to be checked |
ReturnValue
Name | Description |
---|---|
Boolean
|
|
escapeFunctor
fun escapeFunctor(string: String, escapeSingleQuotes: Boolean, escapeDoubleQuotes: Boolean): String
Unconditionally, escapes all occurrences of the characters \n
, \r
, \t
, and \
in string.
Depending on the value of parameters escapeDoubleQuotes and escapeSingleQuotes, occurrences of characters
"
and '
may be escaped as well.
Parameters
Name | Description |
---|---|
string: String
|
the String whose characters must should be escaped |
escapeSingleQuotes: Boolean
|
decides whether single-quote characters (i.e., |
escapeDoubleQuotes: Boolean
|
decides whether double-quote characters (i.e., |
ReturnValue
Name | Description |
---|---|
String
|
either a new String, beginning and ending with |
escapeFunctorIfNecessary
fun escapeFunctorIfNecessary(string: String, escapeSingleQuotes: Boolean, escapeDoubleQuotes: Boolean): String
Escapes all occurrences of the characters \n
, \r
, \t
, and \
in string, but only if a preliminary
check reveals that it contains some character which require escaping.
Depending on the value of parameters escapeDoubleQuotes and escapeSingleQuotes, occurrences of characters
"
and '
may be escaped as well.
Parameters
Name | Description |
---|---|
string: String
|
the String whose characters must should be escaped |
escapeSingleQuotes: Boolean
|
decides whether single-quote characters (i.e., |
escapeDoubleQuotes: Boolean
|
decides whether double-quote characters (i.e., |
ReturnValue
Name | Description |
---|---|
String
|
either a new String, beginning and ending with |
template
fun template(functor: String, arity: Int): Struct
Creates a new Struct with functor as functor and a given amount of anonymous Variables, namely arity. Instances of Struct are always created of the most adequate sub-type of Struct.
Parameters
Name | Description |
---|---|
functor: String
|
|
arity: Int
|
of
fun of(functor: String, args: List<Term>): Struct
Creates a new Struct from the given KtList of Terms. Instances of Struct are always created of the most adequate sub-type of Struct. This implies that, whenever possible, the creation of the new Struct may be delegated to:
- Cons.of
- Rule.of
- Directive.of
- Tuple.of
- Indicator.of
- Block.of
depending on the value of functor and on the amount and sorts of items in args.
Parameters
of
fun of(functor: String, vararg args: Term): Struct
Creates a new Struct from the given Terms. Instances of Struct are always created of the most adequate sub-type of Struct. This implies that, whenever possible, the creation of the new Struct may be delegated to:
- Cons.of
- Rule.of
- Directive.of
- Tuple.of
- Indicator.of
- Block.of
depending on the value of functor and on the amount and sorts provided Terms.
Parameters
of
fun of(functor: String, args: Sequence
Creates a new Struct from the given Sequence of Terms. Instances of Struct are always created of the most adequate sub-type of Struct. This implies that, whenever possible, the creation of the new Struct may be delegated to:
- Cons.of
- Rule.of
- Directive.of
- Tuple.of
- Indicator.of
- Block.of
depending on the value of functor and on the amount and sorts of items in args.
Parameters
of
fun of(functor: String, args: Iterable<Term>): Struct
Creates a new Struct from the given Iterable of Terms. Instances of Struct are always created of the most adequate sub-type of Struct. This implies that, whenever possible, the creation of the new Struct may be delegated to:
- Cons.of
- Rule.of
- Directive.of
- Tuple.of
- Indicator.of
- Block.of
depending on the value of functor and on the amount and sorts of items in args.
Parameters
fold
fun fold(operator: String, terms: List<Term>): Struct
Folds the Terms in terms from left to right, creating binary structures having operator as functor.
Let f
be the value of operator, and let t_i
be the i
-th term in terms.
Then, this method constructs the Structure
f(t_1, f(t_2, ... f(t_n-1, t_n) ...))
Of course, this method will return an instance of either Tuple in case the argument operator is adequate.
Parameters
fold
fun fold(operator: String, terms: List<Term>, terminal: Term?): Struct
Folds the Terms in terms from left to right, creating binary structures having operator as functor.
Let f
be the value of operator, and let t_i
be the i
-th term in terms.
Then, if terminal is non-null, this method constructs the Structure
f(t_1, f(t_2, ... f(t_n, T) ...))
where T
is the value of terminal, and t_n
is the last item in terms.
Conversely, if terminal is null, this method constructs the Structure
f(t_1, f(t_2, ... f(t_n-1, t_n) ...))
Of course, this method will return an instance of either List, or Tuple in case the arguments operator and terminal are adequate.
Parameters
fold
fun fold(operator: String, terms: Sequence
Folds the Terms in terms from left to right, creating binary structures having operator as functor.
Let f
be the value of operator, and let t_i
be the i
-th term in terms.
Then, if terminal is non-null, this method constructs the Structure
f(t_1, f(t_2, ... f(t_n, T) ...))
where T
is the value of terminal, and t_n
is the last item in terms.
Conversely, if terminal is null, this method constructs the Structure
f(t_1, f(t_2, ... f(t_n-1, t_n) ...))
Of course, this method will return an instance of either List, or Tuple in case the arguments operator and terminal are adequate.
Parameters
fold
fun fold(operator: String, terms: Sequence
Folds the Terms in terms from left to right, creating binary structures having operator as functor.
Let f
be the value of operator, and let t_i
be the i
-th term in terms.
Then, this method constructs the Structure
f(t_1, f(t_2, ... f(t_n-1, t_n) ...))
Of course, this method will return an instance of either Tuple in case the argument operator is adequate.
Parameters
fold
fun fold(operator: String, terms: Iterable<Term>, terminal: Term?): Struct
Folds the Terms in terms from left to right, creating binary structures having operator as functor.
Let f
be the value of operator, and let t_i
be the i
-th term in terms.
Then, if terminal is non-null, this method constructs the Structure
f(t_1, f(t_2, ... f(t_n, T) ...))
where T
is the value of terminal, and t_n
is the last item in terms.
Conversely, if terminal is null, this method constructs the Structure
f(t_1, f(t_2, ... f(t_n-1, t_n) ...))
Of course, this method will return an instance of either List, or Tuple in case the arguments operator and terminal are adequate.
Parameters
fold
fun fold(operator: String, terms: Iterable<Term>): Struct
Folds the Terms in terms from left to right, creating binary structures having operator as functor.
Let f
be the value of operator, and let t_i
be the i
-th term in terms.
Then, this method constructs the Structure
f(t_1, f(t_2, ... f(t_n-1, t_n) ...))
Of course, this method will return an instance of either Tuple in case the argument operator is adequate.
Parameters
fold
fun fold(operator: String, vararg terms: Term, terminal: Term?): Struct
Folds the Terms in terms from left to right, creating binary structures having operator as functor.
Let f
be the value of operator, and let t_i
be the i
-th term in terms.
Then, if terminal is non-null, this method constructs the Structure
f(t_1, f(t_2, ... f(t_n, T) ...))
where T
is the value of terminal, and t_n
is the last item in terms.
Conversely, if terminal is null, this method constructs the Structure
f(t_1, f(t_2, ... f(t_n-1, t_n) ...))
Of course, this method will return an instance of either List, or Tuple in case the arguments operator and terminal are adequate.
Parameters
fold
fun fold(operator: String, vararg terms: Term): Struct
Folds the Terms in terms from left to right, creating binary structures having operator as functor.
Let f
be the value of operator, and let t_i
be the i
-th term in terms.
Then, this method constructs the Structure
f(t_1, f(t_2, ... f(t_n-1, t_n) ...))
Of course, this method will return an instance of either Tuple in case the argument operator is adequate.
Parameters
Extensions
parse
fun Struct.Companion.parse(input: String, operators: OperatorSet): Struct
Receiver
Name | Description |
---|---|
Struct.Companion
|
Parameters
Name | Description |
---|---|
input: String
|
|
operators: OperatorSet
|
ReturnValue
Name | Description |
---|---|
Struct
|
Base type for compound Terms, a.k.a. structures. A Struct is characterised by a functor and a given (non-negative) amount of args, namely arity. Each argument can be a Term of any sort.