LogicProgrammingScope

Full term-construction scope of :dsl-core's Prolog DSL: composes every mixin this module defines — MinimalLogicProgrammingScope (structs, lists, clauses), LogicProgrammingScopeWithSubstitutions, LogicProgrammingScopeWithPrologStandardLibrary, LogicProgrammingScopeWithOperators and LogicProgrammingScopeWithVariables — into a single receiver type, self-referential (each mixin's own BaseLogicProgrammingScope type parameter is bound back to LogicProgrammingScope itself) so that BaseLogicProgrammingScope.newScope/scope/rule/fact/... all keep resolving to this same, richest type.

logicProgramming/lp are the idiomatic way to obtain and use one; of and empty exist for callers that need to plug in a custom Termificator or VariablesProvider (or build a scope without immediately entering it). Further modules in the DSL stack (:dsl-unify, :dsl-theory, :dsl-solve) each define their own LogicProgrammingScope extending this one with more mixins (unification, theories, resolution).

See also

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
open val _: Var
Link copied to clipboard
abstract val A: Var
Link copied to clipboard

The at_end_of_stream/0 Atom.

Link copied to clipboard
abstract val B: Var
Link copied to clipboard
abstract val C: Var
Link copied to clipboard
open val cut: Atom

The cut (!/0) Atom.

Link copied to clipboard
abstract val D: Var
Link copied to clipboard
abstract val E: Var
Link copied to clipboard
abstract val emptyBlock: EmptyBlock
Link copied to clipboard
Link copied to clipboard
abstract val F: Var
Link copied to clipboard
abstract val fail: Truth
Link copied to clipboard
abstract val G: Var
Link copied to clipboard
abstract val H: Var
Link copied to clipboard
open val halt: Atom

The halt/0 Atom.

Link copied to clipboard
abstract val I: Var
Link copied to clipboard
abstract val J: Var
Link copied to clipboard
abstract val K: Var
Link copied to clipboard
abstract val L: Var
Link copied to clipboard
abstract val M: Var
Link copied to clipboard
abstract val N: Var
Link copied to clipboard
open val nl: Atom

The nl/0 Atom.

Link copied to clipboard
abstract val O: Var
Link copied to clipboard
abstract val P: Var
Link copied to clipboard
abstract val Q: Var
Link copied to clipboard
abstract val R: Var
Link copied to clipboard
open val repeat: Atom

The repeat/0 Atom.

Link copied to clipboard
abstract val S: Var
Link copied to clipboard
abstract val scope: Scope
Link copied to clipboard
abstract val T: Var
Link copied to clipboard

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

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

The VariablesProvider this scope's own VariablesProvider methods delegate to.

Link copied to clipboard
abstract val W: Var
Link copied to clipboard
abstract val X: Var
Link copied to clipboard
abstract val Y: Var
Link copied to clipboard
abstract val Z: Var

Functions

Link copied to clipboard
open fun abolish(indicator: Any): Struct

Builds an abolish/1 Struct.

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
open fun append(left: Any, right: Any, result: Any): Struct

Builds an append/3 Struct.

Link copied to clipboard
open fun arg(index: Any, compound: Any, argument: Any): Struct

Builds an arg/3 Struct.

Link copied to clipboard
open infix fun Any.arithEq(right: Any): Struct

Builds a =:=/2 Struct (arithmetic equality).

Link copied to clipboard
open infix fun Any.arithNeq(right: Any): Struct

Builds a =\=/2 Struct (arithmetic inequality).

Link copied to clipboard
open fun assert(clause: Any): Struct

Builds an assert/1 Struct.

Link copied to clipboard
open fun asserta(clause: Any): Struct

Builds an asserta/1 Struct.

Link copied to clipboard
open fun assertz(clause: Any): Struct

Builds an assertz/1 Struct.

Link copied to clipboard
open fun at_end_of_stream(alias: Any): Struct

Builds an at_end_of_stream/1 Struct.

Link copied to clipboard
open fun atom(atom: Any): Struct

Builds an atom/1 Struct (type-checking predicate, not to be confused with Struct.functor).

Link copied to clipboard
open fun atom_chars(atom: Any, chars: Any): Struct

Builds an atom_chars/2 Struct.

Link copied to clipboard
open fun atom_codes(atom: Any, codes: Any): Struct

Builds an atom_codes/2 Struct.

Link copied to clipboard
open fun atom_concat(first: Any, second: Any, result: Any): Struct

Builds an atom_concat/3 Struct.

Link copied to clipboard
open fun atom_length(atom: Any, length: Any): Struct

Builds an atom_length/2 Struct.

Link copied to clipboard
open fun atomic(atomic: Any): Struct

Builds an atomic/1 Struct.

Link copied to clipboard
abstract fun atomOf(value: Char): Atom
abstract fun atomOf(value: String): Atom
Link copied to clipboard
open fun bagof(template: Any, goal: Any, bag: Any): Struct

Builds a bagof/3 Struct.

Link copied to clipboard
open fun between(min: Any, max: Any, number: Any): Struct

Builds a between/3 Struct.

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

open fun blockOf(vararg terms: Any): Block

Overload of it.unibo.tuprolog.core.Scope.blockOf accepting plain values, toTerm-ing each of terms.

Link copied to clipboard
open fun call(goal: Any): Struct

Builds a call/1 Struct.

Link copied to clipboard
open fun callable(goal: Any): Struct

Builds a callable/1 Struct.

Link copied to clipboard
open fun catch(goal: Any, error: Any, continuation: Any): Struct

Builds a catch/3 Struct.

Link copied to clipboard
open fun char_code(char: Any, code: Any): Struct

Builds a char_code/2 Struct.

Link copied to clipboard
open fun clause(head: Any, body: Any): Struct

Builds a clause/2 Struct; not to be confused with MinimalLogicProgrammingScope.clause.

open fun clause(function: LogicProgrammingScope.() -> Any): Clause

Runs function with a newScope as its receiver and coerces its result to a Clause: returned as-is if it already is a Clause (e.g. a Rule), or wrapped into a Fact via factOf if it is a plain Struct.

Link copied to clipboard
abstract fun clauseOf(head: Struct?, vararg body: Term): Clause
Link copied to clipboard
open fun compound(struct: Any): Struct

Builds a compound/1 Struct.

Link copied to clipboard
abstract fun consOf(head: Term, tail: Term): Cons

open fun consOf(head: Any, tail: Any): Cons

Overload of it.unibo.tuprolog.core.Scope.consOf accepting plain values, toTerm-ing both head and tail.

Link copied to clipboard
open fun consult(url: Any): Struct

Builds a consult/1 Struct.

Link copied to clipboard
abstract operator fun contains(variable: Var): Boolean
abstract operator fun contains(variable: String): Boolean

open operator fun Substitution.contains(term: Any): Boolean

Alias of containsKey.

Link copied to clipboard

Checks whether this Substitution binds term.

Link copied to clipboard

Checks whether term (auto-toTerm-ed) occurs as a bound value in this Substitution.

Link copied to clipboard
abstract override fun copy(scope: Scope): LogicProgrammingScope

Creates a copy of this scope, backed by scope (see VariablesProvider.copy).

Link copied to clipboard
open fun copy_term(term: Any, copy: Any): Struct

Builds a copy_term/2 Struct.

Link copied to clipboard
open fun current_flag(name: Any, value: Any): Struct

Builds a current_flag/2 Struct.

Link copied to clipboard
open fun current_op(precedence: Any, specifier: Any, functor: Any): Struct

Builds a current_op/3 Struct.

Link copied to clipboard
open fun current_prolog_flag(name: Any, value: Any): Struct

Builds a current_prolog_flag/2 Struct. Deprecated in favor of current_flag.

Link copied to clipboard
open fun directive(function: LogicProgrammingScope.() -> Any): Directive

Runs function with a newScope as its receiver and coerces its result to a Directive via directiveOf.

Link copied to clipboard
abstract fun directiveOf(body1: Term, vararg body: Term): Directive

open fun directiveOf(term: Any, vararg terms: Any): Directive

Overload of it.unibo.tuprolog.core.Scope.directiveOf accepting plain values, toTerm-ing term and each of terms.

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 fun dynamic(indicator: Any): Struct

Builds a dynamic/1 Struct.

Link copied to clipboard
open infix fun Any.eq(right: Any): Struct
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
open fun fact(function: LogicProgrammingScope.() -> Any): Fact

Runs function with a newScope as its receiver and coerces its result to a Fact via factOf.

Link copied to clipboard
abstract fun factOf(head: Struct): Fact

open fun factOf(term: Any): Fact

Overload of it.unibo.tuprolog.core.Scope.factOf accepting a plain value, toTerm-ing term.

Link copied to clipboard
open fun findall(template: Any, goal: Any, bag: Any): Struct

Builds a findall/3 Struct.

Link copied to clipboard
open fun float(number: Any): Struct

Builds a float/1 Struct.

Link copied to clipboard
open fun functor(struct: Any, functor: Any, arity: Any): Struct

Builds a functor/3 Struct.

Link copied to clipboard
abstract operator fun get(variable: String): Var?

open operator fun Substitution.get(term: Any): Term?

Looks up the Term this Substitution binds term to, null if unbound.

Link copied to clipboard
abstract operator fun getValue(thisRef: Any?, property: KProperty<*>): 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 fun ground(term: Any): Struct

Builds a ground/1 Struct.

Link copied to clipboard
open infix fun Any.id(right: Any): Struct

Builds a ==/2 Struct (term structural equality).

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
open fun include(url: Any): Struct

Builds an include/1 Struct.

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 fun initialization(goal: Any): Struct

Builds an initialization/1 Struct.

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

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

Link copied to clipboard
open fun integer(number: Any): Struct

Builds an integer/1 Struct.

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 operator fun String.invoke(term: Any, vararg terms: Any): Struct

Builds a Struct whose functor is this String and whose arguments are term followed by terms.

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

Builds an is/2 Struct (arithmetic evaluation).

Link copied to clipboard
open fun load(url: Any): Struct

Builds a load/1 Struct.

Link copied to clipboard
open fun logicList(vararg items: Any, tail: Any? = null): List

Builds a logic list out of items (each toTerm-ed), optionally ending in tail (also toTerm-ed) rather than the empty list — mirroring it.unibo.tuprolog.core.Scope.logicListFrom's last parameter.

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

open fun logicListOf(vararg terms: Any): List

Overload of it.unibo.tuprolog.core.Scope.logicListOf accepting plain values, toTerm-ing each of terms.

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 fun member(item: Any, list: Any): Struct

Builds a member/2 Struct.

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
open fun naf(goal: Any): Struct

Builds a \+/1 Struct (negation as failure).

Link copied to clipboard
open fun natural(number: Any): Struct

Builds a natural/1 Struct.

Link copied to clipboard
open infix fun Any.neq(right: Any): Struct
Link copied to clipboard

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.nid(right: Any): Struct

Builds a \==/2 Struct (term structural inequality).

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 fun nonvar(number: Any): Struct

Builds a nonvar/1 Struct.

Link copied to clipboard
open fun not(goal: Any): Struct

Builds a not/1 Struct.

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

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

Link copied to clipboard
open fun number(number: Any): Struct

Builds a number/1 Struct.

Link copied to clipboard
open fun number_chars(first: Any, second: Any): Struct

Builds a number_chars/2 Struct.

Link copied to clipboard
open fun number_codes(first: Any, second: Any): Struct

Builds a number_codes/2 Struct.

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 fun op(precedence: Any, specifier: Any, functor: Any): Struct

Builds an op/3 Struct.

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
open fun retract(clause: Any): Struct

Builds a retract/1 Struct.

Link copied to clipboard
open fun retractall(clause: Any): Struct

Builds a retractall/1 Struct.

Link copied to clipboard
open fun rule(function: LogicProgrammingScope.() -> Any): Rule

Runs function with a newScope as its receiver and coerces its result to a Rule — typically built via the head ifbody / head impliedBybody infix builders from LogicProgrammingScopeWithOperators.

Link copied to clipboard
abstract fun ruleOf(head: Struct, body1: Term, vararg body: Term): Rule
Link copied to clipboard
open fun <R> scope(function: LogicProgrammingScope.() -> R): R

Runs function with a newScope as its receiver, isolating any it.unibo.tuprolog.core.Var it creates.

Link copied to clipboard
open fun set_flag(name: Any, value: Any): Struct

Builds a set_flag/2 Struct.

Link copied to clipboard
open fun set_prolog_flag(name: Any, value: Any): Struct

Builds a set_prolog_flag/2 Struct. Deprecated in favor of set_flag.

Link copied to clipboard
open fun setof(template: Any, goal: Any, bag: Any): Struct

Builds a setof/3 Struct.

Link copied to clipboard
open fun solve(goal: Any): Struct

Builds a solve/1 Struct.

Link copied to clipboard
open fun static(indicator: Any): Struct

Builds a static/1 Struct.

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

open fun structOf(functor: String, vararg args: Any): Struct

Overload of it.unibo.tuprolog.core.Scope.structOf accepting plain values, toTerm-ing each of args.

Link copied to clipboard
open fun sub_atom(atom: Any, before: Any, length: Any, after: Any, sub_atom: Any): Struct

Builds a sub_atom/5 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 fun throw(error: Any): Struct

Builds a throw/1 Struct.

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 infix fun Var.to(termObject: Any): Substitution.Unifier

Builds the Substitution.Unifier binding this Var to termObject (auto-toTerm-ed).

open infix fun String.to(termObject: Any): Substitution.Unifier

Builds the Substitution.Unifier binding the Var named by this String (via varOf) to termObject.

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

open fun tupleOf(vararg terms: Any): Tuple

Overload of it.unibo.tuprolog.core.Scope.tupleOf accepting plain values, toTerm-ing each of terms.

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
open infix fun Any.univ(other: Any): Struct

Builds a =../2 Struct (univ).

Link copied to clipboard
open fun var(term: Any): Struct

Builds a var/1 Struct.

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
Link copied to clipboard
open fun write(term: Any): Struct

Builds a write/1 Struct.