Coverage Summary for Class: Subtract (it.unibo.tuprolog.argumentation.core.primitives.utils)
| Class |
Class, %
|
Method, %
|
Branch, %
|
Line, %
|
Instruction, %
|
| Subtract |
100%
(1/1)
|
100%
(2/2)
|
50%
(2/4)
|
100%
(4/4)
|
97.1%
(33/34)
|
package it.unibo.tuprolog.argumentation.core.primitives.utils
import it.unibo.tuprolog.core.List
import it.unibo.tuprolog.core.Substitution
import it.unibo.tuprolog.core.Term
import it.unibo.tuprolog.solve.ExecutionContext
import it.unibo.tuprolog.solve.primitive.Solve
import it.unibo.tuprolog.solve.primitive.TernaryRelation
/**
* subtract(+List, +Removed, ?Rest): the elements of List not in Removed, in order (elements compared as ground terms),
* without the recursion of a Prolog subtract (whose frames would all keep the rest of the list)
*/
internal object Subtract : TernaryRelation.WithoutSideEffects<ExecutionContext>("subtract") {
override fun Solve.Request<ExecutionContext>.computeAllSubstitutions(
first: Term,
second: Term,
third: Term,
): Sequence<Substitution> {
if (first !is List || second !is List) return emptySequence()
val removed = second.toList().toSet()
return unifyWith(third, List.of(first.toList().filter { it !in removed }))
}
}