ExecutionContext

An interface representing the Solver execution context, containing important information that determines its behaviour.

An ExecutionContext is a Solver's entire mutable state, reified as an immutable value: the current substitution, the logicStackTrace, customData, and (via ExecutionContextAware) the unificator, libraries, flags, both knowledge bases, and I/O channels. It is what it.unibo.tuprolog.solve.primitive.Solve.Requests/it.unibo.tuprolog.solve.primitive.Solve.Responses carry around, letting it.unibo.tuprolog.solve.primitive.Primitives and it.unibo.tuprolog.solve.function.LogicFunctions observe (and, via apply/update, derive new versions of) the state of the resolution they're running within, without depending on any concrete resolution strategy.

Because each of these pieces of state is itself an immutable data structure, "mutating" an ExecutionContext always means producing a new instance (e.g. update or apply) rather than changing this one in place -- which keeps every intermediate state snapshot-able, a property resolution strategies rely on for backtracking.

Resolution strategies (e.g. :solve-classic's state-machine solver) are free to extend this interface with whatever extra bookkeeping they personally need; code written against the generic ExecutionContext keeps working regardless of which concrete strategy produced the instance.

See also

Properties

Link copied to clipboard

Custom, implementation- or library-defined data attached to this context, keyed by it.unibo.tuprolog.solve.data.CustomData type.

Link copied to clipboard
abstract val dynamicKb: Theory

Dynamic Knowledge-base, that is a KB that can change executing goals

Link copied to clipboard

How much time elapsed since startTime, computed against the current time instant.

Link copied to clipboard

The time instant by which this entity's execution should be over, computed as startTime (saturating to TimeInstant.MAX_VALUE on overflow).

Link copied to clipboard
abstract val flags: FlagStore

Enabled flags

Link copied to clipboard

The currently open input channels

Link copied to clipboard
abstract val libraries: Runtime

Loaded libraries

Link copied to clipboard
abstract val logicStackTrace: List<Struct>

The Prolog call stacktrace till this ExecutionContext

Link copied to clipboard

The maximum duration this entity's execution is allowed to run for, starting from startTime.

Link copied to clipboard
abstract val operators: OperatorSet

Loaded operators

Link copied to clipboard

The currently open output channels

Link copied to clipboard
abstract val procedure: Struct?

The current procedure being executed, or null if none is (e.g. at the very start of resolution)

Link copied to clipboard

How much time is left before endTime, computed against the current time instant.

Link copied to clipboard

Shortcut for the standard error channel defined in outputChannels. Returns null if the channel is closed

Link copied to clipboard

Shortcut for the standard input channel defined in inputChannels. Returns null if the channel is closed

Link copied to clipboard

Shortcut for the standard output channel defined in outputChannels. Returns null if the channel is closed

Link copied to clipboard
abstract val startTime: TimeInstant

The time instant this entity's execution started at.

Link copied to clipboard
abstract val staticKb: Theory

Static Knowledge-base, that is a KB that can't change executing goals

Link copied to clipboard

The set of current substitution till this context

Link copied to clipboard
abstract val unificator: Unificator
Link copied to clipboard

Shortcut for the warnings channel defined in outputChannels. Returns null if the channel is closed

Functions

Link copied to clipboard
open fun apply(sideEffect: SideEffect): ExecutionContext

Returns a new ExecutionContext, obtained by applying sideEffect to this one, via SideEffect.applyTo.

open fun apply(sideEffects: Iterable<SideEffect>): ExecutionContext

Returns a new ExecutionContext, obtained by applying every sideEffects item, in order, to this one (each one to the result of the previous application).

open fun apply(sideEffects: Sequence<SideEffect>): ExecutionContext

Same as apply for an Iterable, but accepting a Sequence of sideEffects.

Link copied to clipboard
abstract fun createMutableSolver(unificator: Unificator = this.unificator, libraries: Runtime = this.libraries, flags: FlagStore = this.flags, staticKb: Theory = this.staticKb, dynamicKb: Theory = this.dynamicKb, inputChannels: InputStore = this.inputChannels, outputChannels: OutputStore = this.outputChannels): MutableSolver

Same as createSolver, but returns a MutableSolver.

Link copied to clipboard
abstract fun createSolver(unificator: Unificator = this.unificator, libraries: Runtime = this.libraries, flags: FlagStore = this.flags, staticKb: Theory = this.staticKb, dynamicKb: Theory = this.dynamicKb, inputChannels: InputStore = this.inputChannels, outputChannels: OutputStore = this.outputChannels): Solver

Creates a new, independent Solver sharing this context's state (unless overridden by the arguments), to be used e.g. by primitives that need to recursively solve a sub-goal (see it.unibo.tuprolog.solve.primitive.Solve.Request.subSolver).

Link copied to clipboard
abstract fun update(unificator: Unificator = this.unificator, libraries: Runtime = this.libraries, flags: FlagStore = this.flags, staticKb: Theory = this.staticKb, dynamicKb: Theory = this.dynamicKb, operators: OperatorSet = this.operators, inputChannels: InputStore = this.inputChannels, outputChannels: OutputStore = this.outputChannels, customData: CustomDataStore = this.customData): ExecutionContext

Returns a new ExecutionContext, identical to this one except for every explicitly-provided argument, which replaces the corresponding piece of state. Arguments left unspecified default to this context's current value.