
commonMain.it.unibo.tuprolog.solve.stdlib.primitive.FindAll.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of solve-jvm Show documentation
Show all versions of solve-jvm Show documentation
Resolution-agnostic API for logic solvers
package it.unibo.tuprolog.solve.stdlib.primitive
import it.unibo.tuprolog.core.Struct
import it.unibo.tuprolog.core.Term
import it.unibo.tuprolog.solve.ExecutionContext
import it.unibo.tuprolog.solve.Solution
import it.unibo.tuprolog.solve.primitive.Solve
import it.unibo.tuprolog.solve.primitive.TernaryRelation
import it.unibo.tuprolog.unify.Unificator.Companion.mguWith
import it.unibo.tuprolog.core.List as LogicList
object FindAll : TernaryRelation.NonBacktrackable("findall") {
override fun Solve.Request.computeOne(first: Term, second: Term, third: Term): Solve.Response {
ensuringArgumentIsInstantiated(1)
ensuringArgumentIsCallable(1)
val solutions = solve(second as Struct).toList()
val error = solutions.asSequence().filterIsInstance().firstOrNull()
if (error != null) {
return replyException(error.exception.pushContext(context))
}
val mapped = solutions.asSequence()
.filterIsInstance()
.map { first[it.substitution].freshCopy() }
return replyWith(third mguWith LogicList.from(mapped))
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy