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

commonMain.it.unibo.tuprolog.solve.concurrent.stdlib.primitive.Naf.kt Maven / Gradle / Ivy

Go to download

Experimental, state-machine-based implementation of an OR-Concurrent, Prolog-like logic solver, based on Kotlin coroutines

There is a newer version: 1.0.4
Show newest version
package it.unibo.tuprolog.solve.concurrent.stdlib.primitive

import it.unibo.tuprolog.core.Term
import it.unibo.tuprolog.solve.Solution
import it.unibo.tuprolog.solve.concurrent.ConcurrentExecutionContext
import it.unibo.tuprolog.solve.concurrent.ConcurrentSolver
import it.unibo.tuprolog.solve.primitive.Solve
import it.unibo.tuprolog.solve.primitive.UnaryPredicate

/**
 * Negation as failure.
 * Conceptually equivalent to
 * ```
 * \+(G) :- call(G), !, fail.
 * ```
 * in classic Prolog.
 */
object Naf : UnaryPredicate.NonBacktrackable("\\+") {
    override fun Solve.Request.computeOne(first: Term): Solve.Response {
        ensuringArgumentIsCallable(0)
        val solver = subSolver() as ConcurrentSolver
        val solution = solver.solveOnce(first.castToStruct())
        return when (solution) {
            is Solution.Yes -> replyFail()
            is Solution.Halt -> replyException(solution.exception.pushContext(context))
            else -> replySuccess()
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy