commonMain.it.unibo.tuprolog.solve.concurrent.stdlib.primitive.Naf.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of solve-concurrent-jvm Show documentation
Show all versions of solve-concurrent-jvm Show documentation
Experimental, state-machine-based implementation of an OR-Concurrent, Prolog-like logic solver, based on Kotlin coroutines
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