-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
256 additions
and
197 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 0 additions & 20 deletions
20
solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/BacktrackableSideEffect0.kt
This file was deleted.
Oops, something went wrong.
21 changes: 0 additions & 21 deletions
21
solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/BacktrackableSideEffect1.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 0 additions & 24 deletions
24
...rc/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/NonBacktrackableTernaryRelation.kt
This file was deleted.
Oops, something went wrong.
44 changes: 43 additions & 1 deletion
44
solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/PredicateWithoutArguments.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,48 @@ | ||
package it.unibo.tuprolog.solve.primitive | ||
|
||
import it.unibo.tuprolog.core.Substitution | ||
import it.unibo.tuprolog.core.Term | ||
import it.unibo.tuprolog.solve.ExecutionContext | ||
import it.unibo.tuprolog.solve.Solve | ||
|
||
/** A base class to implement predicates with zero argument */ | ||
abstract class PredicateWithoutArguments<E : ExecutionContext>(operator: String) : PrimitiveWrapper<E>(operator, 0) | ||
abstract class PredicateWithoutArguments<E : ExecutionContext>(operator: String) : PrimitiveWrapper<E>(operator, 0) { | ||
/** Template method that should compute the response of the application of this predicate to a term [Term] */ | ||
protected abstract fun Solve.Request<E>.computeAll(): Sequence<Solve.Response> | ||
|
||
final override fun uncheckedImplementation(request: Solve.Request<E>): Sequence<Solve.Response> { | ||
return request.computeAll() | ||
} | ||
|
||
abstract class WithoutSideEffects<E : ExecutionContext>(operator: String) : PredicateWithoutArguments<E>(operator) { | ||
protected abstract fun Solve.Request<E>.computeAllSubstitutions(): Sequence<Substitution> | ||
|
||
final override fun Solve.Request<E>.computeAll(): Sequence<Solve.Response> { | ||
return computeAllSubstitutions().map { replyWith(it) } | ||
} | ||
} | ||
|
||
abstract class NonBacktrackable<E : ExecutionContext>(operator: String) : PredicateWithoutArguments<E>(operator) { | ||
protected abstract fun Solve.Request<E>.computeOne(): Solve.Response | ||
|
||
final override fun Solve.Request<E>.computeAll(): Sequence<Solve.Response> { | ||
return sequenceOf(computeOne()) | ||
} | ||
} | ||
|
||
abstract class Functional<E : ExecutionContext>(operator: String) : NonBacktrackable<E>(operator) { | ||
protected abstract fun Solve.Request<E>.computeOneSubstitution(): Substitution | ||
|
||
final override fun Solve.Request<E>.computeOne(): Solve.Response { | ||
return replyWith(computeOneSubstitution()) | ||
} | ||
} | ||
|
||
abstract class Predicative<E : ExecutionContext>(operator: String) : NonBacktrackable<E>(operator) { | ||
protected abstract fun Solve.Request<E>.compute(): Boolean | ||
|
||
final override fun Solve.Request<E>.computeOne(): Solve.Response { | ||
return if (compute()) replySuccess() else replyFail() | ||
} | ||
} | ||
} |
21 changes: 0 additions & 21 deletions
21
solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/SideEffect0.kt
This file was deleted.
Oops, something went wrong.
26 changes: 0 additions & 26 deletions
26
solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/SideEffect1.kt
This file was deleted.
Oops, something went wrong.
30 changes: 0 additions & 30 deletions
30
solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/TermRelation.kt
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.