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
Custom, implementation- or library-defined data attached to this context, keyed by it.unibo.tuprolog.solve.data.CustomData type.
How much time elapsed since startTime, computed against the current time instant.
The time instant by which this entity's execution should be over, computed as startTime (saturating to TimeInstant.MAX_VALUE on overflow).
The currently open input channels
The Prolog call stacktrace till this ExecutionContext
The maximum duration this entity's execution is allowed to run for, starting from startTime.
Loaded operators
The currently open output channels
How much time is left before endTime, computed against the current time instant.
Shortcut for the standard error channel defined in outputChannels. Returns null if the channel is closed
Shortcut for the standard input channel defined in inputChannels. Returns null if the channel is closed
Shortcut for the standard output channel defined in outputChannels. Returns null if the channel is closed
The time instant this entity's execution started at.
The set of current substitution till this context
Shortcut for the warnings channel defined in outputChannels. Returns null if the channel is closed
Functions
Returns a new ExecutionContext, obtained by applying sideEffect to this one, via SideEffect.applyTo.
Returns a new ExecutionContext, obtained by applying every sideEffects item, in order, to this one (each one to the result of the previous application).
Same as apply for an Iterable, but accepting a Sequence of sideEffects.
Same as createSolver, but returns a MutableSolver.
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).
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.