LogicProgrammingScopeWithOperators

Adds infix/operator builders mirroring Prolog's own arithmetic, relational and logical operators, so that Structs (and Rules, for if/impliedBy) can be written as Kotlin expressions instead of nested BaseLogicProgrammingScope.toTerm/structOf calls:

logicProgramming {
"X" `is` ("Y" + 1) // Struct: is(X, +(Y, 1))
("X" greaterThan 0) and ("Y" lowerThan 10) // Struct: ','(>(X, 0), <(Y, 10))
"even"("X") `if` ("X" rem 2 eq 0) // Rule: even(X) :- =(rem(X, 2), 0)
}

Each Prolog operator is overloaded once per receiver type (Term, Any, Number, Boolean, Char, String, ...) only where Kotlin's own operator-overload resolution requires it to disambiguate from conflicting stdlib operators (e.g. Number.plus); the Any-receiver versions (equalsTo, and, is, ...) cover every other case directly, toTerm-ing both operands.

Inheritors

Properties

Link copied to clipboard
open val _: Var
Link copied to clipboard
abstract val emptyBlock: EmptyBlock
Link copied to clipboard
Link copied to clipboard
abstract val fail: Truth
Link copied to clipboard

The Termificator used by toTerm to convert arbitrary values into Terms within this scope.

Link copied to clipboard
abstract val variables: Map<String, Var>

Functions

Link copied to clipboard
open infix fun Any.and(other: Any): Struct

Builds a conjunction (, /2, right-associative), i.e. a Tuple: if this value is already a Tuple, other is appended to it as one more item, rather than nesting a new 2-ary tuple around it — so a and b and c flattens to a single 3-ary tuple (a, b, c) rather than (a, (b, c)).

Link copied to clipboard
abstract fun anonymous(): Var
Link copied to clipboard
abstract fun atomOf(value: Char): Atom
abstract fun atomOf(value: String): Atom
Link copied to clipboard
abstract fun blockOf(terms: Iterable<Term>): Block
abstract fun blockOf(terms: Sequence<Term>): Block
abstract fun blockOf(vararg terms: Term): Block
Link copied to clipboard
abstract fun clauseOf(head: Struct?, vararg body: Term): Clause
Link copied to clipboard
abstract fun consOf(head: Term, tail: Term): Cons
Link copied to clipboard
abstract operator fun contains(variable: Var): Boolean
abstract operator fun contains(variable: String): Boolean
Link copied to clipboard
abstract fun directiveOf(body1: Term, vararg body: Term): Directive
Link copied to clipboard
open operator fun Term.div(other: Any): Indicator

Builds an Indicator out of this Term (the name) and other (the arity), e.g. "foo" / 2. Note this overload does not build a Prolog //2 struct — use structOf directly for that.

open operator fun Boolean.div(other: Any): Struct
open operator fun Char.div(other: Any): Struct
open operator fun String.div(other: Any): Struct

Same as the Number receiver overload of div above, for a non-Number left-hand side.

open operator fun Number.div(other: Any): Struct

Builds a //2 Struct (Prolog division), e.g. "X" / 2. Unlike the Term receiver overload of div above, this does not build an Indicator.

Link copied to clipboard
open infix fun Any.equalsTo(other: Any): Struct

Builds a Struct whose functor is '='/2 (term unification operator).

Link copied to clipboard
abstract fun factOf(head: Struct): Fact
Link copied to clipboard
abstract operator fun get(variable: String): Var?
Link copied to clipboard
open infix fun Any.greaterThan(other: Any): Struct

Builds a >/2 Struct (arithmetic greater-than).

Link copied to clipboard
open infix fun Any.greaterThanOrEqualsTo(other: Any): Struct

Builds a >=/2 Struct (arithmetic greater-than-or-equal).

Link copied to clipboard
open infix fun Any.if(other: Any): Rule

Alias of impliedBy reading in head-first order: head ifbody builds the Rule head :- body.

open fun Any.if(vararg other: Any): Rule

Vararg overload of if: head.if(body1, body2, ...) builds the Rule head :- (body1, body2, ...).

Link copied to clipboard
open infix fun Any.impliedBy(other: Any): Rule

Builds the Rule this :- other, i.e. other implies (is the body of a rule whose head is) this value.

open fun Any.impliedBy(vararg other: Any): Rule

Vararg overload of impliedBy: wraps other into a single conjunction (via Tuple.wrapIfNeeded) before building the Rule, so a multi-goal body can be listed as separate arguments instead of chained with and.

Link copied to clipboard
abstract fun indicatorOf(name: Term, arity: Term): Indicator
abstract fun indicatorOf(name: String, arity: Int): Indicator
Link copied to clipboard
open infix fun Any.intDiv(other: Any): Struct

Builds a ///2 Struct (integer division).

Link copied to clipboard
abstract fun intOf(value: Byte): Integer
abstract fun intOf(value: Int): Integer
abstract fun intOf(value: Long): Integer
abstract fun intOf(value: Short): Integer
abstract fun intOf(value: String): Integer
abstract fun intOf(value: BigInteger): Integer
abstract fun intOf(value: String, radix: Int): Integer
Link copied to clipboard
open infix fun Any.is(other: Any): Struct

Builds an is/2 Struct (arithmetic evaluation).

Link copied to clipboard
abstract fun logicListFrom(terms: Iterable<Term>, last: Term?): List
abstract fun logicListFrom(terms: Sequence<Term>, last: Term?): List
abstract fun logicListFrom(vararg terms: Term, last: Term?): List
Link copied to clipboard
abstract fun logicListOf(terms: Iterable<Term>): List
abstract fun logicListOf(terms: Sequence<Term>): List
abstract fun logicListOf(vararg terms: Term): List
Link copied to clipboard
open infix fun Any.lowerThan(other: Any): Struct

Builds a </2 Struct (arithmetic lower-than).

Link copied to clipboard
open infix fun Any.lowerThanOrEqualsTo(other: Any): Struct

Builds an =</2 Struct (arithmetic lower-than-or-equal).

Link copied to clipboard
open operator fun Term.minus(other: Any): Struct

Builds a -/2 Struct, e.g. "X" - 1.

open operator fun Boolean.minus(other: Any): Struct
open operator fun Char.minus(other: Any): Struct
open operator fun Number.minus(other: Any): Struct
open operator fun String.minus(other: Any): Struct

Same as the Term receiver overload of minus above, for a non-Term left-hand side.

Link copied to clipboard
abstract fun newScope(): S

Creates a fresh scope of type S, backed by a brand-new, empty Scope — so that it.unibo.tuprolog.core.Vars created within it are unrelated to the ones created through this scope. Used by builders such as MinimalLogicProgrammingScope.rule/MinimalLogicProgrammingScope.fact to isolate each clause's variables.

Link copied to clipboard
open infix fun Any.nonGreaterThan(other: Any): Struct
Link copied to clipboard
open infix fun Any.nonLowerThan(other: Any): Struct
Link copied to clipboard
open infix fun Any.notEqualsTo(other: Any): Struct

Builds a \=/2 Struct (term non-unifiability).

Link copied to clipboard
abstract fun numOf(value: Byte): Integer
abstract fun numOf(value: Double): Real
abstract fun numOf(value: Float): Real
abstract fun numOf(value: Int): Integer
abstract fun numOf(value: Long): Integer
abstract fun numOf(value: Number): Numeric
abstract fun numOf(value: Short): Integer
abstract fun numOf(value: String): Numeric
abstract fun numOf(value: BigDecimal): Real
abstract fun numOf(value: BigInteger): Integer
Link copied to clipboard
open infix fun Any.or(other: Any): Struct

Builds a ;/2 Struct (disjunction).

Link copied to clipboard
open operator fun Term.plus(other: Any): Struct

Builds a +/2 Struct, e.g. 1 + "X".

open operator fun Boolean.plus(other: Any): Struct
open operator fun Char.plus(other: Any): Struct
open operator fun Number.plus(other: Any): Struct

Same as the Term receiver overload of plus above, for a non-Term left-hand side.

Link copied to clipboard
open infix fun Any.pow(other: Any): Struct

Builds a **/2 Struct (arithmetic power).

Link copied to clipboard
abstract fun realOf(value: Double): Real
abstract fun realOf(value: Float): Real
abstract fun realOf(value: String): Real
abstract fun realOf(value: BigDecimal): Real
Link copied to clipboard
open infix operator fun Term.rem(other: Any): Struct

Builds a rem/2 Struct (integer remainder).

open infix operator fun Boolean.rem(other: Any): Struct
open infix operator fun Char.rem(other: Any): Struct
open infix operator fun Number.rem(other: Any): Struct
open infix operator fun String.rem(other: Any): Struct

Same as the Term receiver overload of rem above, for a non-Term left-hand side.

Link copied to clipboard
abstract fun ruleOf(head: Struct, body1: Term, vararg body: Term): Rule
Link copied to clipboard
abstract fun structOf(functor: String, args: Iterable<Term>): Struct
abstract fun structOf(functor: String, args: List<Term>): Struct
abstract fun structOf(functor: String, args: Sequence<Term>): Struct
abstract fun structOf(functor: String, vararg args: Term): Struct
Link copied to clipboard
abstract fun substitutionOf(assignments: Iterable<Pair<Var, Term>>): Substitution
abstract fun substitutionOf(assignments: Sequence<Pair<Var, Term>>): Substitution
abstract fun substitutionOf(vararg assignments: Pair<String, Term>): Substitution
Link copied to clipboard
open infix fun Any.sup(other: Any): Struct

Builds a ^/2 Struct (existential quantification, e.g. for bagof/setof, or integer power).

Link copied to clipboard
open infix fun Any.then(other: Any): Struct

Builds a ->/2 Struct (if-then).

Link copied to clipboard
open operator fun Term.times(other: Any): Struct

Builds a */2 Struct, e.g. "X" * 2.

open operator fun Boolean.times(other: Any): Struct
open operator fun Char.times(other: Any): Struct
open operator fun Number.times(other: Any): Struct
open operator fun String.times(other: Any): Struct

Same as the Term receiver overload of times above, for a non-Term left-hand side.

Link copied to clipboard
open fun <T : Term> Any.toSpecificSubTypeOfTerm(type: KClass<T>, converter: (Struct) -> T): T

Converts this value into a Term (via toTerm) and coerces it to type: returned as-is if it already is a type, passed through converter if it is a Struct (e.g. to turn a plain Struct into a Fact), or rejected otherwise.

Link copied to clipboard
open fun Any.toTerm(): Term

Converts this value into a Term, via termificator. See Termificator.termify for the conversion rules.

Link copied to clipboard
abstract fun truthOf(value: Boolean): Truth
Link copied to clipboard
abstract fun tupleOf(terms: Iterable<Term>): Tuple
abstract fun tupleOf(terms: Sequence<Term>): Tuple
abstract fun tupleOf(vararg terms: Term): Tuple
Link copied to clipboard
abstract fun unifierOf(assignments: Iterable<Pair<Var, Term>>): Substitution.Unifier
abstract fun unifierOf(assignments: Sequence<Pair<Var, Term>>): Substitution.Unifier
abstract fun unifierOf(vararg assignments: Pair<String, Term>): Substitution.Unifier
Link copied to clipboard
abstract fun varOf(name: Char): Var
abstract fun varOf(name: String): Var
Link copied to clipboard
abstract fun whatever(): Var
Link copied to clipboard
abstract fun where(lambda: Scope.() -> Unit): Scope
Link copied to clipboard
abstract fun <R> with(lambda: Scope.() -> R): R