LogicProgrammingScopeWithResolution

Adds resolution-driving sugar to LogicProgrammingScopeWithUnificator: implements MutableSolver itself (forwarding to defaultSolver, e.g. via MutableSolver by defaultSolver as LogicProgrammingScopeImpl does), so solve/solveOnce/solveList and every knowledge-base-mutating operation (MutableSolver.assertZ, MutableSolver.retract, ...) are callable directly on the scope — plus staticKb/dynamicKb shorthands for loading a whole knowledge base at once, and solverOf for building additional, independent solvers sharing this scope's solverFactory/unificator.

This is what turns the DSL from a pure term/theory builder into something that can actually run queries:

prolog {
staticKb(
fact { "parent"("abraham", "isaac") },
rule { "ancestor"("X", "Y") `if` "parent"("X", "Y") },
)
for (solution in solve("ancestor"("abraham", "X"))) {
if (solution is it.unibo.tuprolog.solve.Solution.Yes) {
println(solution.substitution["X"])
}
}
}

solve (and the rest of the MutableSolver/it.unibo.tuprolog.solve.Solver surface) is inherited, undocumented here, from it.unibo.tuprolog.solve.Solver and MutableSolver themselves.

Type Parameters

S

the concrete, self-referential scope type (see it.unibo.tuprolog.dsl.BaseLogicProgrammingScope).

Inheritors

Properties

Link copied to clipboard
open val _: Var
Link copied to clipboard
abstract val context: Substitution
Link copied to clipboard

The MutableSolver this scope forwards MutableSolver/it.unibo.tuprolog.solve.Solver operations (solve, staticKb, dynamicKb, assertZ, ...) to. Built once when the scope is created (see LogicProgrammingScopeImpl's secondary constructor) via SolverFactory.mutableSolverOf.

Link copied to clipboard
abstract val dynamicKb: Theory
Link copied to clipboard
abstract val emptyBlock: EmptyBlock
Link copied to clipboard
Link copied to clipboard
abstract val fail: Truth
Link copied to clipboard
abstract val flags: FlagStore
Link copied to clipboard
Link copied to clipboard
abstract val libraries: Runtime
Link copied to clipboard
abstract val operators: OperatorSet
Link copied to clipboard
Link copied to clipboard

The SolverFactory this scope's defaultSolver was created from, and that solverOf builds further solvers from by default.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
abstract val staticKb: Theory
Link copied to clipboard
Link copied to clipboard
abstract val unificator: Unificator
Link copied to clipboard
abstract val variables: Map<String, Var>
Link copied to clipboard

Functions

Link copied to clipboard
abstract fun anonymous(): Var
Link copied to clipboard
abstract fun appendDynamicKb(theory: Theory)
Link copied to clipboard
abstract fun appendStaticKb(theory: Theory)
Link copied to clipboard
abstract fun assertA(clause: Clause)
abstract fun assertA(fact: Struct)
Link copied to clipboard
abstract fun assertZ(clause: Clause)
abstract fun assertZ(fact: Struct)
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 override fun clone(): MutableSolver
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 copy(unificator: Unificator): S
abstract override fun copy(unificator: Unificator, libraries: Runtime, flags: FlagStore, staticKb: Theory, dynamicKb: Theory, stdIn: InputChannel<String>, stdOut: OutputChannel<String>, stdErr: OutputChannel<String>, warnings: OutputChannel<Warning>): MutableSolver
Link copied to clipboard
abstract fun directiveOf(body1: Term, vararg body: Term): Directive
Link copied to clipboard
open fun dynamicKb(theory: Theory)

Replaces defaultSolver's dynamic knowledge base with theory; see MutableSolver.loadDynamicKb.

open fun dynamicKb(clauses: Iterable<Clause>)
open fun dynamicKb(clauses: Sequence<Clause>)
open fun dynamicKb(vararg clauses: Clause)

Replaces defaultSolver's dynamic knowledge base with a Theory indexing clauses; see MutableSolver.loadDynamicClauses.

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
abstract fun indicatorOf(name: Term, arity: Term): Indicator
abstract fun indicatorOf(name: String, arity: Int): Indicator
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 fun loadDynamicClauses(clauses: Iterable<Clause>)
open fun loadDynamicClauses(clauses: Sequence<Clause>)
open fun loadDynamicClauses(vararg clauses: Clause)
Link copied to clipboard
abstract fun loadDynamicKb(theory: Theory)
Link copied to clipboard
abstract fun loadLibrary(library: Library)
Link copied to clipboard
open fun loadStaticClauses(clauses: Iterable<Clause>)
open fun loadStaticClauses(clauses: Sequence<Clause>)
open fun loadStaticClauses(vararg clauses: Clause)
Link copied to clipboard
abstract fun loadStaticKb(theory: Theory)
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 fun match(term1: Term, term2: Term): Boolean
open fun match(term1: Term, term2: Term, occurCheckEnabled: Boolean): Boolean
Link copied to clipboard
open fun merge(substitution1: Substitution, substitution2: Substitution): Substitution
abstract fun merge(substitution1: Substitution, substitution2: Substitution, occurCheckEnabled: Boolean): Substitution
Link copied to clipboard
open fun mgu(term1: Term, term2: Term): Substitution
abstract fun mgu(term1: Term, term2: Term, occurCheckEnabled: Boolean): Substitution
Link copied to clipboard
abstract fun newScope(): S
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
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
abstract fun resetDynamicKb()
Link copied to clipboard
abstract fun resetStaticKb()
Link copied to clipboard
abstract fun retract(clause: Clause): RetractResult<Theory>
abstract fun retract(fact: Struct): RetractResult<Theory>
Link copied to clipboard
abstract fun retractAll(clause: Clause): RetractResult<Theory>
abstract fun retractAll(fact: Struct): RetractResult<Theory>
Link copied to clipboard
abstract fun ruleOf(head: Struct, body1: Term, vararg body: Term): Rule
Link copied to clipboard
abstract fun setFlag(flag: NotableFlag)
abstract fun setFlag(flag: Pair<String, Term>)
abstract fun setFlag(name: String, value: Term)
Link copied to clipboard
abstract fun setRuntime(libraries: Runtime)
Link copied to clipboard
abstract fun setStandardError(stdErr: OutputChannel<String>)
Link copied to clipboard
abstract fun setStandardInput(stdIn: InputChannel<String>)
Link copied to clipboard
abstract fun setStandardOutput(stdOut: OutputChannel<String>)
Link copied to clipboard
abstract fun setWarnings(warnings: OutputChannel<Warning>)
Link copied to clipboard
open fun solve(goal: Struct): Sequence<Solution>
abstract fun solve(goal: Struct, options: SolveOptions): Sequence<Solution>
open fun solve(goal: Struct, timeout: TimeDuration): Sequence<Solution>
Link copied to clipboard
open fun solveList(goal: Struct): List<Solution>
open fun solveList(goal: Struct, options: SolveOptions): List<Solution>
open fun solveList(goal: Struct, timeout: TimeDuration): List<Solution>
Link copied to clipboard
open fun solveOnce(goal: Struct): Solution
open fun solveOnce(goal: Struct, options: SolveOptions): Solution
open fun solveOnce(goal: Struct, timeout: TimeDuration): Solution
Link copied to clipboard
open fun solverOf(unificator: Unificator = this.unificator, otherLibraries: Runtime = solverFactory.defaultRuntime, flags: FlagStore = solverFactory.defaultFlags, staticKb: Theory = solverFactory.defaultStaticKb, dynamicKb: Theory = solverFactory.defaultDynamicKb, stdIn: InputChannel<String> = solverFactory.defaultInputChannel, stdOut: OutputChannel<String> = solverFactory.defaultOutputChannel, stdErr: OutputChannel<String> = solverFactory.defaultErrorChannel, warnings: OutputChannel<Warning> = solverFactory.defaultWarningsChannel): MutableSolver

Builds a brand-new MutableSolver from solverFactory (defaulting every argument to solverFactory's default* values, except unificator which defaults to this scope's own), including solverFactory's standard-library builtins — see SolverFactory.mutableSolverWithDefaultBuiltins. Unlike defaultSolver, this returns an independent solver each time it's called, not the one backing this scope's solve/staticKb calls.

Link copied to clipboard
open fun staticKb(theory: Theory)

Replaces defaultSolver's static knowledge base with theory; see MutableSolver.loadStaticKb.

open fun staticKb(clauses: Iterable<Clause>)
open fun staticKb(clauses: Sequence<Clause>)
open fun staticKb(vararg clauses: Clause)

Replaces defaultSolver's static knowledge base with a Theory indexing clauses; see MutableSolver.loadStaticClauses.

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 fun <T : Term> Any.toSpecificSubTypeOfTerm(type: KClass<T>, converter: (Struct) -> T): T
Link copied to clipboard
open fun Any.toTerm(): Term
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
open fun unify(term1: Term, term2: Term): Term?
open fun unify(term1: Term, term2: Term, occurCheckEnabled: Boolean): Term?
Link copied to clipboard
abstract fun unloadLibrary(library: Library)
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