diff --git a/solve-classic/src/commonMain/kotlin/it/unibo/tuprolog/solve/ClassicExecutionContext.kt b/solve-classic/src/commonMain/kotlin/it/unibo/tuprolog/solve/ClassicExecutionContext.kt index 802cd6634..04975520c 100644 --- a/solve-classic/src/commonMain/kotlin/it/unibo/tuprolog/solve/ClassicExecutionContext.kt +++ b/solve-classic/src/commonMain/kotlin/it/unibo/tuprolog/solve/ClassicExecutionContext.kt @@ -110,6 +110,18 @@ data class ClassicExecutionContext( ) } + override fun apply(sideEffect: SideEffect): ClassicExecutionContext { + return super.apply(sideEffect) as ClassicExecutionContext + } + + override fun apply(sideEffects: Iterable): ClassicExecutionContext { + return super.apply(sideEffects) as ClassicExecutionContext + } + + override fun apply(sideEffects: Sequence): ClassicExecutionContext { + return super.apply(sideEffects) as ClassicExecutionContext + } + override fun toString(): String { return "ClassicExecutionContext(" + "query=$query, " + diff --git a/solve-classic/src/commonMain/kotlin/it/unibo/tuprolog/solve/fsm/StatePrimitiveExecution.kt b/solve-classic/src/commonMain/kotlin/it/unibo/tuprolog/solve/fsm/StatePrimitiveExecution.kt index a005ce6d2..863fcd1d1 100644 --- a/solve-classic/src/commonMain/kotlin/it/unibo/tuprolog/solve/fsm/StatePrimitiveExecution.kt +++ b/solve-classic/src/commonMain/kotlin/it/unibo/tuprolog/solve/fsm/StatePrimitiveExecution.kt @@ -9,20 +9,16 @@ import it.unibo.tuprolog.utils.Cursor internal data class StatePrimitiveExecution(override val context: ClassicExecutionContext) : AbstractState(context) { - private fun ClassicExecutionContext.copyFromCurrentPrimitive(goals: Cursor? = null, - parentProcedure: Boolean = false, - substitution: Substitution? = null): ClassicExecutionContext { - return copy( + private fun ClassicExecutionContext.copyFromCurrentPrimitive( + goals: Cursor? = null, + parentProcedure: Boolean = false, + substitution: Substitution? = null + ): ClassicExecutionContext { + val ctx = primitives.current?.let { apply(it.sideEffects) } ?: this + return ctx.copy( goals = goals ?: this.goals, procedure = if (parentProcedure) parent?.procedure else procedure, primitives = Cursor.empty(), - libraries = primitives.current?.libraries ?: libraries, - flags = primitives.current?.flags ?: flags, - staticKb = primitives.current?.staticKb ?: staticKb, - dynamicKb = primitives.current?.dynamicKb ?: dynamicKb, - operators = primitives.current?.operators ?: operators, - inputChannels = primitives.current?.inputChannels ?: inputChannels, - outputChannels = primitives.current?.outputChannels ?: outputChannels, substitution = (substitution ?: this.substitution) as Substitution.Unifier, step = nextStep() ) diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/Solve.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/Solve.kt index 7e486fe38..d237f3492 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/Solve.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/Solve.kt @@ -84,7 +84,7 @@ sealed class Solve { ) = Response( Solution.Yes(query, substitution), sideEffectManager, - *sideEffects + *sideEffects ) /** Creates a new failed [Response] to this Request */