All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.it.unibo.tuprolog.solve.function.ExpressionReducer.kt Maven / Gradle / Ivy

There is a newer version: 1.0.4
Show newest version
package it.unibo.tuprolog.solve.function

import it.unibo.tuprolog.core.Struct
import it.unibo.tuprolog.core.Term
import it.unibo.tuprolog.solve.ExecutionContext
import it.unibo.tuprolog.solve.primitive.Solve

/**
 * Reduces a [Term] as an expression by evaluating all the evaluable sub-terms it contains
 * w.r.t. the loaded functions provided through [request].
 * If the input expression is non-evaluable, it remains unaffected and no error is thrown
 *
 * @param request the request of the primitive in which the evaluation should happen
 * @param index the index of the argument being evalued in the aforementioned primitive
 */
class ExpressionReducer(
    request: Solve.Request,
    index: Int? = null,
) : AbstractEvaluator(request, index) {
    override fun unevaluable(struct: Struct): Term {
        return if (struct.arity > 0) {
            struct.setArgs(struct.argsSequence.map { it.accept(this).apply { dynamicCheck(struct) } })
        } else {
            struct
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy