VariablesProvider

A Scope extended with 26 pre-declared Var properties, one per uppercase Latin letter (A to Z), for quickly sketching terms in Kotlin code without spelling out varOf("X") for every commonly-named variable. Being also a Kotlin property delegate provider (via getValue), a VariablesProvider lets a Kotlin val declaration mint (or fetch) a same-named Scope variable directly:

val provider = VariablesProvider.of()
val x by provider // equivalent to `val x = provider.varOf("X")`

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
open val _: Var

Shorthand for anonymous, letting Kotlin code refer to a fresh anonymous variable as _, mirroring Prolog's own syntax.

Link copied to clipboard
abstract val A: Var

Shorthand for varOf("A").

Link copied to clipboard
abstract val B: Var

Shorthand for varOf("B").

Link copied to clipboard
abstract val C: Var

Shorthand for varOf("C").

Link copied to clipboard
abstract val D: Var

Shorthand for varOf("D").

Link copied to clipboard
abstract val E: Var

Shorthand for varOf("E").

Link copied to clipboard
abstract val emptyBlock: EmptyBlock

Shorthand for the empty logic block, i.e. EmptyBlock.

Link copied to clipboard

Shorthand for the empty logic list, i.e. EmptyList.

Link copied to clipboard
abstract val F: Var

Shorthand for varOf("F").

Link copied to clipboard
abstract val fail: Truth

Shorthand for Truth.FAIL.

Link copied to clipboard
abstract val G: Var

Shorthand for varOf("G").

Link copied to clipboard
abstract val H: Var

Shorthand for varOf("H").

Link copied to clipboard
abstract val I: Var

Shorthand for varOf("I").

Link copied to clipboard
abstract val J: Var

Shorthand for varOf("J").

Link copied to clipboard
abstract val K: Var

Shorthand for varOf("K").

Link copied to clipboard
abstract val L: Var

Shorthand for varOf("L").

Link copied to clipboard
abstract val M: Var

Shorthand for varOf("M").

Link copied to clipboard
abstract val N: Var

Shorthand for varOf("N").

Link copied to clipboard
abstract val O: Var

Shorthand for varOf("O").

Link copied to clipboard
abstract val P: Var

Shorthand for varOf("P").

Link copied to clipboard
abstract val Q: Var

Shorthand for varOf("Q").

Link copied to clipboard
abstract val R: Var

Shorthand for varOf("R").

Link copied to clipboard
abstract val S: Var

Shorthand for varOf("S").

Link copied to clipboard
abstract val scope: Scope

The underlying Scope this VariablesProvider delegates variable creation/caching to.

Link copied to clipboard
abstract val T: Var

Shorthand for varOf("T").

Link copied to clipboard
abstract val U: Var

Shorthand for varOf("U").

Link copied to clipboard
abstract val V: Var

Shorthand for varOf("V").

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

The Variables created so far through this Scope, indexed by their simple Var.name.

Link copied to clipboard
abstract val W: Var

Shorthand for varOf("W").

Link copied to clipboard
abstract val X: Var

Shorthand for varOf("X").

Link copied to clipboard
abstract val Y: Var

Shorthand for varOf("Y").

Link copied to clipboard
abstract val Z: Var

Shorthand for varOf("Z").

Functions

Link copied to clipboard
abstract fun anonymous(): Var

Creates a fresh, unrelated anonymous Var. See Var.anonymous.

Link copied to clipboard
abstract fun atomOf(value: Char): Atom
abstract fun atomOf(value: String): Atom

Creates an Atom with the given value. See Atom.of.

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

Creates a Block out of terms. See Block.of.

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

Creates a Clause with the given (possibly null) head and body. See Clause.of.

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

Creates a Cons with the given head and tail. See Cons.of.

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

Checks whether variable was created through this Scope.

abstract operator fun contains(variable: String): Boolean

Checks whether a variable named variable was created through this Scope.

Link copied to clipboard
abstract fun copy(scope: Scope = this.scope): VariablesProvider

Creates a copy of this VariablesProvider, backed by scope (defaulting to this one's own scope).

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

Creates a Directive with the given body. See Directive.of.

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

Creates a Fact with the given head. See Fact.of.

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

Retrieves the Var named variable previously created through this Scope, or null if none exists yet.

Link copied to clipboard
abstract operator fun getValue(thisRef: Any?, property: KProperty<*>): Var

Property-delegate hook letting val x by variablesProvider resolve to variablesProvider.varOf("X").

Link copied to clipboard
abstract fun indicatorOf(name: Term, arity: Term): Indicator
abstract fun indicatorOf(name: String, arity: Int): Indicator

Creates an Indicator with the given name and arity. See Indicator.of.

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: BigInteger): Integer

Creates an Integer out of value. See Integer.of.

abstract fun intOf(value: String): Integer

Parses value into an Integer. See Integer.of.

abstract fun intOf(value: String, radix: Int): Integer

Parses value, expressed in the given radix, into an Integer. See Integer.of.

Link copied to clipboard
abstract fun logicListFrom(terms: Iterable<Term>, last: Term? = null): List
abstract fun logicListFrom(terms: Sequence<Term>, last: Term? = null): List
abstract fun logicListFrom(vararg terms: Term, last: Term? = null): List

Creates a (possibly partial) logic LogicList out of terms, terminated by last. See List.from.

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

Creates a logic LogicList out of terms. See List.of.

Link copied to clipboard
abstract fun numOf(value: Byte): Integer
abstract fun numOf(value: Int): Integer
abstract fun numOf(value: Long): Integer
abstract fun numOf(value: Short): Integer
abstract fun numOf(value: BigInteger): Integer

Creates an Integer out of value. See Numeric.of.

abstract fun numOf(value: Double): Real
abstract fun numOf(value: Float): Real
abstract fun numOf(value: BigDecimal): Real

Creates a Real out of value. See Numeric.of.

abstract fun numOf(value: Number): Numeric

Creates a Numeric out of value. See Numeric.of.

abstract fun numOf(value: String): Numeric

Parses value into a Numeric, preferring Integer and falling back to Real. See Numeric.of.

Link copied to clipboard
abstract fun realOf(value: Double): Real
abstract fun realOf(value: Float): Real
abstract fun realOf(value: BigDecimal): Real

Creates a Real out of value. See Real.of.

abstract fun realOf(value: String): Real

Parses value into a Real. See Real.of.

Link copied to clipboard
abstract fun ruleOf(head: Struct, body1: Term, vararg body: Term): Rule

Creates a Rule with the given head and body. See Rule.of.

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

Creates a Struct with the given functor and args. See Struct.of.

Link copied to clipboard
abstract fun substitutionOf(assignments: Iterable<Pair<Var, Term>>): Substitution
abstract fun substitutionOf(assignments: Sequence<Pair<Var, Term>>): Substitution

Creates a Substitution out of the given Var-Term.

abstract fun substitutionOf(vararg assignments: Pair<String, Term>): Substitution

Creates a Substitution out of the given Var.name-Term.

Link copied to clipboard
abstract fun truthOf(value: Boolean): Truth

Creates a Truth out of value. See Truth.of.

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

Creates a Tuple out of terms. See Tuple.of.

Link copied to clipboard
abstract fun unifierOf(assignments: Iterable<Pair<Var, Term>>): Substitution.Unifier
abstract fun unifierOf(assignments: Sequence<Pair<Var, Term>>): Substitution.Unifier

Creates a Substitution.Unifier out of the given Var-Term.

abstract fun unifierOf(vararg assignments: Pair<String, Term>): Substitution.Unifier

Creates a Substitution.Unifier out of the given Var.name-Term.

Link copied to clipboard
abstract fun varOf(name: Char): Var
abstract fun varOf(name: String): Var

Retrieves the Var named name, creating and caching a new one on first request.

Link copied to clipboard
abstract fun whatever(): Var

Alias for anonymous.

Link copied to clipboard
abstract fun where(lambda: Scope.() -> Unit): Scope

Runs lambda with this Scope as its receiver, for its side effects, then returns this same Scope. Useful to populate a Scope with variables/terms without capturing the result of the last expression.

Link copied to clipboard
abstract fun <R> with(lambda: Scope.() -> R): R

Runs lambda with this Scope as its receiver, returning whatever lambda produces. This is the idiomatic way of using a Scope: Scope.empty().with { ruleOf(...) }, or more concisely Scope.empty { ruleOf(...) } via the companion overloads.