From f7c64526a60d604c723ccea488a3d9b2d5dc81ba Mon Sep 17 00:00:00 2001 From: Lorenzo Rizzato Date: Thu, 14 May 2020 19:14:35 +0200 Subject: [PATCH 01/20] + substitutions chapter --- .../variables-and-scopes.md | 70 ++++++++++++++++++- 1 file changed, 69 insertions(+), 1 deletion(-) diff --git a/documentation/src/orchid/resources/wiki/Rationale and Architecture/variables-and-scopes.md b/documentation/src/orchid/resources/wiki/Rationale and Architecture/variables-and-scopes.md index 9b99c9687..6cfacda55 100644 --- a/documentation/src/orchid/resources/wiki/Rationale and Architecture/variables-and-scopes.md +++ b/documentation/src/orchid/resources/wiki/Rationale and Architecture/variables-and-scopes.md @@ -107,4 +107,72 @@ In particular, thanks to the instance of `Scope` created behind the scenes, vari meaning that, if more variables exists within the to-be-copied `Term`, which have the same name, then all fresh copies of such variables will have the same complete name. Thus, for instance, a fresh copy of the `f(X, g(X))` would be something like `f(X_1, g(X_1))` -instead of `f(X_1, g(X_2))`. \ No newline at end of file +instead of `f(X_1, g(X_2))`. + +## Substitutions + +Substitutions represent variable bindings, and are obtained through unification operations (see [Unification](substitutions-and-unification)). Indeed, Substitution is actually a subclass of Map, and its methods are implemented by delegating to a Map instance. + +Substitution has two types: Unifier and Fail. The former is a type representing a substitution as described in the Prolog standard, while the latter is a singleton instance used where a unifier cannot be found. + +### Substitution creation + +Substitution instances can be created using the `Substitution.of` factory method. Although these instances are usually obtained as a result of unification operations, it still may be useful to be aware of this simple implementation detail. + +For example, Substitution instances can be created by specifying a series of variable-term pairs: + +```kotlin +Scope.empty { + val substitution = Substitution.of( + varOf("X") to atomOf("abraham"), + varOf("Y") to atomOf("isaac"), + ) +} +``` + +Keep in mind that `Substitution.of` will check for contradictions, and may possibly return Fail objects. + +### Substitution application + +Substitutions can be applied to terms through the `applyTo(term: Term)` method. Calling this method will return a new Term equivalent to the starting one, but all variables will be replaced according to the provided bindings. + +For example, by applying the substitution `{X -> abraham}` on term `father(X, isaac)`: + +```kotlin +Scope.empty { + val term = structOf("father", varOf("X"), atomOf("isaac")) + val substitution = Substitution.of(varOf("X") to atomOf("abraham")) + + val result = substitution.applyTo(term) +} +``` + +we will get the `father(abraham, isaac)` ground term. + +### Substitution composition + +Substitutions can be composed through the `plus()` method, which is also available as the infix operator `+`. + +For example, say we want to compose a substitution `{X -> abraham}` with `{Y -> isaac}` within the same scope. In order to do so, we would write: + +```kotlin +Scope.empty { + val sub1 = Substitution.of(varOf("X"), atomOf("abraham")) + val sub2 = Substitution.of(varOf("Y"), atomOf("isaac")) + + val substitution = sub1 + sub2 +} +``` + +In 2P-Kt, unlike in the Prolog standard, composing two contradicting substitution will lead to a failure, yielding the Fail singleton object. For example, if we tried to bind a variable `X` with two different atoms: + +```kotlin +Scope.empty { + val sub1 = Substitution.of(varOf("X"), atomOf("abraham")) + val sub2 = Substitution.of(varOf("X"), atomOf("nahor")) + + val substitution = sub1 + sub2 // contradiction! +} +``` + +we would cause a contradiction, and the composition would fail. \ No newline at end of file From cb467a26943a20ecc5b825e7c265b21031a1bdc8 Mon Sep 17 00:00:00 2001 From: Lorenzo Rizzato Date: Thu, 14 May 2020 19:18:11 +0200 Subject: [PATCH 02/20] fix text --- .../wiki/Rationale and Architecture/variables-and-scopes.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/documentation/src/orchid/resources/wiki/Rationale and Architecture/variables-and-scopes.md b/documentation/src/orchid/resources/wiki/Rationale and Architecture/variables-and-scopes.md index 6cfacda55..5d9dc5ff5 100644 --- a/documentation/src/orchid/resources/wiki/Rationale and Architecture/variables-and-scopes.md +++ b/documentation/src/orchid/resources/wiki/Rationale and Architecture/variables-and-scopes.md @@ -147,7 +147,7 @@ Scope.empty { } ``` -we will get the `father(abraham, isaac)` ground term. +we will get the `father(abraham, isaac)` ground term as a result. ### Substitution composition From 4b2209d5cf39eec892fdb145bf7100900547588f Mon Sep 17 00:00:00 2001 From: Lorenzo Rizzato Date: Thu, 14 May 2020 19:30:41 +0200 Subject: [PATCH 03/20] change -> to = --- .../wiki/Rationale and Architecture/variables-and-scopes.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/documentation/src/orchid/resources/wiki/Rationale and Architecture/variables-and-scopes.md b/documentation/src/orchid/resources/wiki/Rationale and Architecture/variables-and-scopes.md index 5d9dc5ff5..4677f00ad 100644 --- a/documentation/src/orchid/resources/wiki/Rationale and Architecture/variables-and-scopes.md +++ b/documentation/src/orchid/resources/wiki/Rationale and Architecture/variables-and-scopes.md @@ -136,7 +136,7 @@ Keep in mind that `Substitution.of` will check for contradictions, and may possi Substitutions can be applied to terms through the `applyTo(term: Term)` method. Calling this method will return a new Term equivalent to the starting one, but all variables will be replaced according to the provided bindings. -For example, by applying the substitution `{X -> abraham}` on term `father(X, isaac)`: +For example, by applying the substitution `{X = abraham}` on term `father(X, isaac)`: ```kotlin Scope.empty { @@ -153,7 +153,7 @@ we will get the `father(abraham, isaac)` ground term as a result. Substitutions can be composed through the `plus()` method, which is also available as the infix operator `+`. -For example, say we want to compose a substitution `{X -> abraham}` with `{Y -> isaac}` within the same scope. In order to do so, we would write: +For example, say we want to compose a substitution `{X = abraham}` with `{Y = isaac}` within the same scope. In order to do so, we would write: ```kotlin Scope.empty { From ca01550cd4c3124e9361e7295313f61c20ac425a Mon Sep 17 00:00:00 2001 From: Lorenzo Rizzato Date: Thu, 21 May 2020 18:17:58 +0200 Subject: [PATCH 04/20] + unification chapter --- .../substitutions-and-unification.md | 87 ++++++++++++++++++- 1 file changed, 86 insertions(+), 1 deletion(-) diff --git a/documentation/src/orchid/resources/wiki/Rationale and Architecture/substitutions-and-unification.md b/documentation/src/orchid/resources/wiki/Rationale and Architecture/substitutions-and-unification.md index bb602672f..9f3e22fc2 100644 --- a/documentation/src/orchid/resources/wiki/Rationale and Architecture/substitutions-and-unification.md +++ b/documentation/src/orchid/resources/wiki/Rationale and Architecture/substitutions-and-unification.md @@ -1 +1,86 @@ -TODO: write \ No newline at end of file +Unification is the process of matching two terms by finding a suitable substitution to their variables, also known as the _most general unifier_ (MGU hereafter). + +In 2P-Kt, unification utilities are encapsulated in the `Unificator` interface, which is partially implemented by the `AbstractUnificator` class. + +Unification is provided by three functions: +- `mgu(Term, Term): Substitution` tries to unify two Terms, returning the MGU if it succeds, or the Fail object otherwise; +- `match(Term, Term): Boolean` tells whether two Terms match each other, that is there's a MGU for them; +- `unify(Term, Term): Term?` tries to unify two Terms, possibly returning the unified Term in case of success. + +## Creating Unificators + +Unificator's companion object provides three default implementations of the Unificator interface: + +- `default` uses plain `equals` to determine Terms identity (like `strict`) and exploits a LRU cache with a fixed default capacity; +- `naive()` compares numbers by their value; +- `strict()` uses plain `equals` to determine Terms identity. + +The `strict` and `naive` versions can also be called by giving them a starting unification _context_ to start with, which is simply a `Substitution` object containing pre-determined variable bindings that the user wishes to employ when unifying. Such behaviour can be obtained as follows: + +```kotlin +val context: Substitution = ... +val strict = Unificator.strict() +val strictWithContext = Unificator.strict(context) +``` + +### Caching Unificators through decoration + +Optionally, unificators can also be enabled to cache their results between several operations. This is easily accomplished by _decorating_ them through the companion object's `cached` method, which wraps them in a CachedUnificator instance, allowing them to store a limited amount of requests (default is 32) and repeating their response when necessary. + +```kotlin +val unificator = Unificator.default + +val cached = Unificator.cached(unificator) // default cache size +val smaller = Unificator.cached(unificator, capacity = 5) // stores up to 5 requests +``` + +By default, requests are cached following a LRU strategy (least recently used). + +## Enabling/disabling occurs-check + +The unification algorithm performs occurs-check by default. However, this check can be disabled by specifying the `occurCheckEnabled: Boolean` parameter when calling the aforementioned methods. For example: + +```kotlin +val unificator = Unificator.default +val subtitution = unificator.mgu(term1, term2, occurCheckEnabled = false) +``` + +Note that this mechanism does not work when using the infix, operator-like variants of the unification functions. + +## Infix variants + +Unificator's companion object provides a handy alternative for calling unification functions in the form of **infix** methods. + +These variants -- namely `mguWith`, `matches`, `unifyWith` -- allow developers to employ unification features in a more light and intuitive way, by exploting the syntactic tools provided by the Kotlin language. + +This allows us to compute the MGU between two Terms simply by writing: + +```kotlin +import it.unibo.tuprolog.unify.Unificator +... +val substitution = term1 mguWith term2 +``` + +Keep in mind that these default variants **always perform occurs-check**, since they employ the implementations provided by `Unificator.default`. + +## Implementing different unification strategies + +Implementing custom Unificators comes down to defining the `checkTermsEquality` method from the `AbstractUnificator` class. This method is used by the unification algorithm to test whether two terms are matching. + +Say we want to define a Unificator that compares numeric values by their absolute value. Then, we can write a new instance of `AbstractUnificator` that compares numbers like so: + +```kotlin +val unificator = object : AbstractUnificator() { + override fun checkTermsEquality(first: Term, second: Term): Boolean = when { + first is Integer && second is Integer -> + first.value.absoluteValue.compareTo(second.value.absoluteValue) == 0 + first is Numeric && second is Numeric -> + first.decimalValue.absoluteValue.compareTo(second.decimalValue.absoluteValue) == 0 + else -> first == second + } +} +``` + +Notice how the default case still relies on checking term equality through the `==` operator, which aliases the `Term.equals` method. + +This example shows how you can create custom unificator instances on-the-fly, but the same approach can be adopted if you want to extend the hierarchy by proper sub-classing. \ No newline at end of file From a6bc8ede41b31f79211485342e7e69f22d000c35 Mon Sep 17 00:00:00 2001 From: Lorenzo Rizzato Date: Fri, 22 May 2020 17:13:49 +0200 Subject: [PATCH 05/20] fix example indentation --- .../substitutions-and-unification.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/documentation/src/orchid/resources/wiki/Rationale and Architecture/substitutions-and-unification.md b/documentation/src/orchid/resources/wiki/Rationale and Architecture/substitutions-and-unification.md index 9f3e22fc2..92f534e5c 100644 --- a/documentation/src/orchid/resources/wiki/Rationale and Architecture/substitutions-and-unification.md +++ b/documentation/src/orchid/resources/wiki/Rationale and Architecture/substitutions-and-unification.md @@ -72,12 +72,12 @@ Say we want to define a Unificator that compares numeric values by their absolut ```kotlin val unificator = object : AbstractUnificator() { override fun checkTermsEquality(first: Term, second: Term): Boolean = when { - first is Integer && second is Integer -> - first.value.absoluteValue.compareTo(second.value.absoluteValue) == 0 - first is Numeric && second is Numeric -> - first.decimalValue.absoluteValue.compareTo(second.decimalValue.absoluteValue) == 0 - else -> first == second - } + first is Integer && second is Integer -> + first.value.absoluteValue.compareTo(second.value.absoluteValue) == 0 + first is Numeric && second is Numeric -> + first.decimalValue.absoluteValue.compareTo(second.decimalValue.absoluteValue) == 0 + else -> first == second + } } ``` From faa30d80e674547e5f8e7a2d8f8d3cd65fc096fb Mon Sep 17 00:00:00 2001 From: Giovanni Ciatto Date: Mon, 8 Jun 2020 10:18:33 +0200 Subject: [PATCH 06/20] add retract/1 --- .../tuprolog/solve/stdlib/CommonBuiltins.kt | 1 + .../primitive/BacktrackableSideEffect0.kt | 20 +++++++++++ .../primitive/BacktrackableSideEffect1.kt | 21 ++++++++++++ .../solve/stdlib/primitive/Retract.kt | 34 +++++++++++++++++++ 4 files changed, 76 insertions(+) create mode 100644 solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/BacktrackableSideEffect0.kt create mode 100644 solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/BacktrackableSideEffect1.kt create mode 100644 solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/Retract.kt diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/CommonBuiltins.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/CommonBuiltins.kt index 92eb14bb0..4f3420434 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/CommonBuiltins.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/CommonBuiltins.kt @@ -38,6 +38,7 @@ object CommonBuiltins : AliasedLibrary by Library.of( NonVar, NotUnifiableWith, Number, + Retract, Sleep, TermIdentical, TermNotIdentical, diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/BacktrackableSideEffect0.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/BacktrackableSideEffect0.kt new file mode 100644 index 000000000..bed26d56d --- /dev/null +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/BacktrackableSideEffect0.kt @@ -0,0 +1,20 @@ +package it.unibo.tuprolog.solve.stdlib.primitive + +import it.unibo.tuprolog.solve.ExecutionContext +import it.unibo.tuprolog.solve.Solve + +abstract class BacktrackableSideEffect0(typeName: String) : PredicateWithoutArguments(typeName) { + override fun uncheckedImplementation(request: Solve.Request): Sequence = + accept(request) + + abstract fun accept(request: Solve.Request): Sequence + + companion object { + fun of(typeName: String, consumer: (Solve.Request) -> Sequence): BacktrackableSideEffect0 = + object : BacktrackableSideEffect0(typeName) { + override fun accept(request: Solve.Request): Sequence { + return consumer(request) + } + } + } +} \ No newline at end of file diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/BacktrackableSideEffect1.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/BacktrackableSideEffect1.kt new file mode 100644 index 000000000..9b60693a0 --- /dev/null +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/BacktrackableSideEffect1.kt @@ -0,0 +1,21 @@ +package it.unibo.tuprolog.solve.stdlib.primitive + +import it.unibo.tuprolog.core.Term +import it.unibo.tuprolog.solve.ExecutionContext +import it.unibo.tuprolog.solve.Solve + +abstract class BacktrackableSideEffect1(typeName: String) : UnaryPredicate(typeName) { + override fun uncheckedImplementation(request: Solve.Request): Sequence = + accept(request, request.arguments[0][request.context.substitution]) + + abstract fun accept(request: Solve.Request, term: Term): Sequence + + companion object { + fun of(typeName: String, consumer: (Solve.Request, Term) -> Sequence): BacktrackableSideEffect1 = + object : BacktrackableSideEffect1(typeName) { + override fun accept(request: Solve.Request, term: Term): Sequence { + return consumer(request, term) + } + } + } +} \ No newline at end of file diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/Retract.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/Retract.kt new file mode 100644 index 000000000..dabf7c61a --- /dev/null +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/Retract.kt @@ -0,0 +1,34 @@ +package it.unibo.tuprolog.solve.stdlib.primitive + +import it.unibo.tuprolog.core.* +import it.unibo.tuprolog.core.Var +import it.unibo.tuprolog.solve.ExecutionContext +import it.unibo.tuprolog.solve.Solve +import it.unibo.tuprolog.theory.RetractResult +import it.unibo.tuprolog.unify.Unificator.Companion.mguWith + +object Retract: BacktrackableSideEffect1("retract") { + override fun accept(request: Solve.Request, term: Term): Sequence { + request.ensuringArgumentIsStruct(0) + val clause = if (term is Clause) term else Rule.of(term as Struct, Var.anonymous()) + return sequence { + var dynamicKb = request.context.dynamicKb + while (true) { + val result = dynamicKb.retract(clause) + if (result is RetractResult.Success) { + dynamicKb = result.theory + val substitution = when (term) { + is Clause -> (term mguWith result.firstClause) as Substitution.Unifier + else -> (term mguWith result.firstClause.head!!) as Substitution.Unifier + } + yield( + request.replySuccess(substitution = substitution, dynamicKb = dynamicKb) + ) + } else { + break + } + } + } + } + +} \ No newline at end of file From e5f7031ef9fa478df3d39623a68ebd6b3bda540a Mon Sep 17 00:00:00 2001 From: Giovanni Ciatto Date: Mon, 8 Jun 2020 10:19:50 +0200 Subject: [PATCH 07/20] let asser*/1 accept rules --- .../tuprolog/solve/stdlib/primitive/AbstractAssert.kt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/AbstractAssert.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/AbstractAssert.kt index b3df35b35..5175a55b6 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/AbstractAssert.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/AbstractAssert.kt @@ -1,5 +1,7 @@ package it.unibo.tuprolog.solve.stdlib.primitive +import it.unibo.tuprolog.core.Clause +import it.unibo.tuprolog.core.Fact import it.unibo.tuprolog.core.Struct import it.unibo.tuprolog.core.Term import it.unibo.tuprolog.solve.ExecutionContext @@ -8,12 +10,13 @@ import it.unibo.tuprolog.solve.Solve abstract class AbstractAssert(suffix: String, private val before: Boolean) : SideEffect1("assert$suffix") { override fun accept(request: Solve.Request, term: Term): Solve.Response = with(request.ensuringArgumentIsStruct(0)) { + val clause = if (term is Clause) term else Fact.of(term as Struct) replySuccess( dynamicKb = context.dynamicKb.let { if (before) { - it.assertA(term as Struct) + it.assertA(clause) } else { - it.assertZ(term as Struct) + it.assertZ(clause) } } ) From 182c9ecd3436771c95a4b5cccd41cd2c3c3845e8 Mon Sep 17 00:00:00 2001 From: Giovanni Ciatto Date: Mon, 8 Jun 2020 10:20:27 +0200 Subject: [PATCH 08/20] add tests for asser*/1 and retract/1 --- .../systemtest/ClassicSolverSystemTesting.kt | 10 ++++ .../systemtest/StreamsSolverSystemTesting.kt | 10 ++++ .../it/unibo/tuprolog/solve/SolverTest.kt | 2 + .../it/unibo/tuprolog/solve/SolverTestImpl.kt | 54 +++++++++++++++++++ 4 files changed, 76 insertions(+) diff --git a/solve-classic/src/commonTest/kotlin/it/unibo/tuprolog/solve/systemtest/ClassicSolverSystemTesting.kt b/solve-classic/src/commonTest/kotlin/it/unibo/tuprolog/solve/systemtest/ClassicSolverSystemTesting.kt index e73192153..1e5d47028 100644 --- a/solve-classic/src/commonTest/kotlin/it/unibo/tuprolog/solve/systemtest/ClassicSolverSystemTesting.kt +++ b/solve-classic/src/commonTest/kotlin/it/unibo/tuprolog/solve/systemtest/ClassicSolverSystemTesting.kt @@ -278,4 +278,14 @@ class ClassicSolverSystemTesting : SolverFactory, SolverTest { override fun testBasicBacktracking4() { prototype.testBasicBacktracking4() } + + @Test + override fun testAssertRules() { + prototype.testAssertRules() + } + + @Test + override fun testRetract() { + prototype.testRetract() + } } diff --git a/solve-streams/src/commonTest/kotlin/it/unibo/tuprolog/solve/systemtest/StreamsSolverSystemTesting.kt b/solve-streams/src/commonTest/kotlin/it/unibo/tuprolog/solve/systemtest/StreamsSolverSystemTesting.kt index 598f98467..fec25c6c6 100644 --- a/solve-streams/src/commonTest/kotlin/it/unibo/tuprolog/solve/systemtest/StreamsSolverSystemTesting.kt +++ b/solve-streams/src/commonTest/kotlin/it/unibo/tuprolog/solve/systemtest/StreamsSolverSystemTesting.kt @@ -283,4 +283,14 @@ class StreamsSolverSystemTesting : SolverFactory, SolverTest { override fun testBasicBacktracking4() { prototype.testBasicBacktracking4() } + + @Test + override fun testAssertRules() { + prototype.testAssertRules() + } + + @Test + override fun testRetract() { + prototype.testRetract() + } } diff --git a/test-solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/SolverTest.kt b/test-solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/SolverTest.kt index be9718f86..4422e78c3 100644 --- a/test-solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/SolverTest.kt +++ b/test-solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/SolverTest.kt @@ -162,5 +162,7 @@ interface SolverTest { fun testDisjunction() fun testDisjunctionWithUnification() fun testMember() + fun testAssertRules() + fun testRetract() } diff --git a/test-solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/SolverTestImpl.kt b/test-solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/SolverTestImpl.kt index 0dd0f014b..806c5fd32 100644 --- a/test-solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/SolverTestImpl.kt +++ b/test-solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/SolverTestImpl.kt @@ -54,6 +54,8 @@ import it.unibo.tuprolog.solve.stdlib.rule.Arrow import it.unibo.tuprolog.solve.stdlib.rule.Member import it.unibo.tuprolog.solve.stdlib.rule.Not import it.unibo.tuprolog.solve.stdlib.rule.Semicolon +import it.unibo.tuprolog.theory.Theory +import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertNotNull import kotlin.test.assertTrue @@ -873,4 +875,56 @@ internal class SolverTestImpl(private val solverFactory: SolverFactory) : Solver assertEquals(constants.size + 1, solutions.size) } } + + override fun testAssertRules() { + prolog { + val solver = solverFactory.solverWithDefaultBuiltins() + + val query = "assertz"("f"(2) impliedBy false) and "asserta"("f"(1) impliedBy true) + + val solutions = solver.solve(query, maxDuration).toList() + + assertSolutionEquals( + ktListOf(query.yes()), + solutions + ) + + assertEquals( + ktListOf( + factOf(structOf("f", numOf(1))), + ruleOf(structOf("f", numOf(2)), atomOf("false")) + ), + solver.dynamicKb.toList() + ) + } + } + + override fun testRetract() { + prolog { + val solver = solverFactory.solverWithDefaultBuiltins( + dynamicKb = theoryOf( + factOf(structOf("f", numOf(1))), + ruleOf(structOf("f", numOf(2)), atomOf("false")) + ) + ) + + val query = "retract"("f"("X")) + + val solutions = solver.solve(query, maxDuration).toList() + + assertSolutionEquals( + ktListOf( + query.yes("X" to 1), + query.yes("X" to 2) + ), + solutions + ) + + assertEquals( + ktListOf(), + solver.dynamicKb.toList() + ) + assertEquals(0L, solver.dynamicKb.size) + } + } } \ No newline at end of file From 2b000fb513711b346ba514b20cb98a4e157c13e4 Mon Sep 17 00:00:00 2001 From: Giovanni Ciatto Date: Mon, 8 Jun 2020 10:23:24 +0200 Subject: [PATCH 09/20] fix bug in backtracking of primitives for :solve-classic --- .../tuprolog/solve/fsm/StateBacktracking.kt | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/solve-classic/src/commonMain/kotlin/it/unibo/tuprolog/solve/fsm/StateBacktracking.kt b/solve-classic/src/commonMain/kotlin/it/unibo/tuprolog/solve/fsm/StateBacktracking.kt index 268e24642..c32248482 100644 --- a/solve-classic/src/commonMain/kotlin/it/unibo/tuprolog/solve/fsm/StateBacktracking.kt +++ b/solve-classic/src/commonMain/kotlin/it/unibo/tuprolog/solve/fsm/StateBacktracking.kt @@ -5,15 +5,19 @@ import it.unibo.tuprolog.solve.Solution internal data class StateBacktracking(override val context: ClassicExecutionContext) : AbstractState(context) { override fun computeNext(): State { - return with(context) { - if (choicePoints === null || !choicePoints.hasOpenAlternatives) { - StateEnd( - solution = Solution.No(query), - context = copy(step = nextStep()) - ) + val choicePoints = context.choicePoints + return if (choicePoints.let { it === null || !it.hasOpenAlternatives }) { + StateEnd( + solution = Solution.No(context.query), + context = context.copy(step = nextStep()) + ) + } else { + val choicePointContext = choicePoints!!.pathToRoot.first { it.alternatives.hasNext } + val nextContext = choicePointContext.backtrack(nextStep(), context.startTime) + if (nextContext.primitives.hasNext) { + StatePrimitiveExecution(nextContext) } else { - val choicePointContext = choicePoints.pathToRoot.first { it.alternatives.hasNext } - StateRuleExecution(choicePointContext.backtrack(nextStep(), context.startTime)) + StateRuleExecution(nextContext) } } } From 61b0373d1d30712464638b2dc7ccb8d2be419e75 Mon Sep 17 00:00:00 2001 From: Giovanni Ciatto Date: Mon, 8 Jun 2020 10:24:17 +0200 Subject: [PATCH 10/20] fix bug :repl concerning the way solutions are consumed --- .../kotlin/it/unibo/tuprolog/ui/repl/TuPrologUtils.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/repl/src/commonMain/kotlin/it/unibo/tuprolog/ui/repl/TuPrologUtils.kt b/repl/src/commonMain/kotlin/it/unibo/tuprolog/ui/repl/TuPrologUtils.kt index 7b0606628..6254abe4a 100644 --- a/repl/src/commonMain/kotlin/it/unibo/tuprolog/ui/repl/TuPrologUtils.kt +++ b/repl/src/commonMain/kotlin/it/unibo/tuprolog/ui/repl/TuPrologUtils.kt @@ -2,6 +2,7 @@ package it.unibo.tuprolog.ui.repl import com.github.ajalt.clikt.core.ProgramResult import com.github.ajalt.clikt.output.TermUi +import com.github.ajalt.clikt.output.defaultCliktConsole import it.unibo.tuprolog.core.TermFormatter import it.unibo.tuprolog.core.format import it.unibo.tuprolog.core.parsing.ParseException @@ -102,7 +103,7 @@ object TuPrologUtils { var first = true while (solutions.hasNext()) { if (!first) { - val cmd = TermUi.prompt("", promptSuffix = "")?.trim() + val cmd = defaultCliktConsole().promptForLine("", false)?.trim() if (cmd != ";") break } else { first = false From 4c8b6e52b5d851d136360c834083db5fdab466da Mon Sep 17 00:00:00 2001 From: Giovanni Ciatto Date: Mon, 8 Jun 2020 10:32:15 +0200 Subject: [PATCH 11/20] add system test for natural/1 --- .../systemtest/ClassicSolverSystemTesting.kt | 5 +++++ .../systemtest/StreamsSolverSystemTesting.kt | 5 +++++ .../it/unibo/tuprolog/solve/SolverTest.kt | 1 + .../it/unibo/tuprolog/solve/SolverTestImpl.kt | 17 +++++++++++++++++ 4 files changed, 28 insertions(+) diff --git a/solve-classic/src/commonTest/kotlin/it/unibo/tuprolog/solve/systemtest/ClassicSolverSystemTesting.kt b/solve-classic/src/commonTest/kotlin/it/unibo/tuprolog/solve/systemtest/ClassicSolverSystemTesting.kt index 1e5d47028..85ee2c3b9 100644 --- a/solve-classic/src/commonTest/kotlin/it/unibo/tuprolog/solve/systemtest/ClassicSolverSystemTesting.kt +++ b/solve-classic/src/commonTest/kotlin/it/unibo/tuprolog/solve/systemtest/ClassicSolverSystemTesting.kt @@ -288,4 +288,9 @@ class ClassicSolverSystemTesting : SolverFactory, SolverTest { override fun testRetract() { prototype.testRetract() } + + @Test + override fun testNatural() { + prototype.testNatural() + } } diff --git a/solve-streams/src/commonTest/kotlin/it/unibo/tuprolog/solve/systemtest/StreamsSolverSystemTesting.kt b/solve-streams/src/commonTest/kotlin/it/unibo/tuprolog/solve/systemtest/StreamsSolverSystemTesting.kt index fec25c6c6..1c86453ea 100644 --- a/solve-streams/src/commonTest/kotlin/it/unibo/tuprolog/solve/systemtest/StreamsSolverSystemTesting.kt +++ b/solve-streams/src/commonTest/kotlin/it/unibo/tuprolog/solve/systemtest/StreamsSolverSystemTesting.kt @@ -293,4 +293,9 @@ class StreamsSolverSystemTesting : SolverFactory, SolverTest { override fun testRetract() { prototype.testRetract() } + + @Test + override fun testNatural() { + prototype.testNatural() + } } diff --git a/test-solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/SolverTest.kt b/test-solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/SolverTest.kt index 4422e78c3..dd9c56911 100644 --- a/test-solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/SolverTest.kt +++ b/test-solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/SolverTest.kt @@ -164,5 +164,6 @@ interface SolverTest { fun testMember() fun testAssertRules() fun testRetract() + fun testNatural() } diff --git a/test-solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/SolverTestImpl.kt b/test-solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/SolverTestImpl.kt index 806c5fd32..c52c0fcfc 100644 --- a/test-solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/SolverTestImpl.kt +++ b/test-solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/SolverTestImpl.kt @@ -927,4 +927,21 @@ internal class SolverTestImpl(private val solverFactory: SolverFactory) : Solver assertEquals(0L, solver.dynamicKb.size) } } + + override fun testNatural() { + prolog { + val solver = solverFactory.solverWithDefaultBuiltins() + + val query = "natural"("X") and "natural"("X") + + val n = 100 + + val solutions = solver.solve(query, maxDuration).take(n).toList() + + assertSolutionEquals( + (0 until n).map { query.yes("X" to it) }, + solutions + ) + } + } } \ No newline at end of file From 095cd405c9020b13963fcf90a81a49e9db99495d Mon Sep 17 00:00:00 2001 From: Giovanni Ciatto Date: Mon, 8 Jun 2020 10:34:41 +0200 Subject: [PATCH 12/20] add sleep/1 and retract/1 to api test --- .../commonMain/kotlin/it/unibo/tuprolog/solve/SolverTestImpl.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test-solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/SolverTestImpl.kt b/test-solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/SolverTestImpl.kt index c52c0fcfc..9bc3e13ca 100644 --- a/test-solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/SolverTestImpl.kt +++ b/test-solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/SolverTestImpl.kt @@ -104,6 +104,8 @@ internal class SolverTestImpl(private val solverFactory: SolverFactory) : Solver assertHasPredicateInAPI(NonVar) assertHasPredicateInAPI(NotUnifiableWith) assertHasPredicateInAPI(Number) + assertHasPredicateInAPI(Retract) + assertHasPredicateInAPI(Sleep) assertHasPredicateInAPI(TermIdentical) assertHasPredicateInAPI(TermNotIdentical) assertHasPredicateInAPI(UnifiesWith) From f24ec768c9b18cbc47d09e36dde820c1deacc44c Mon Sep 17 00:00:00 2001 From: Giovanni Ciatto Date: Thu, 11 Jun 2020 13:59:50 +0200 Subject: [PATCH 13/20] console=plain in whole gradle --- gradle.properties | 1 + repl/gradle.properties | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) delete mode 100644 repl/gradle.properties diff --git a/gradle.properties b/gradle.properties index ec097f132..62171c05c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,4 @@ +org.gradle.console=plain kotlin.code.style=official javaVersion=8 diff --git a/repl/gradle.properties b/repl/gradle.properties deleted file mode 100644 index e7a574c9b..000000000 --- a/repl/gradle.properties +++ /dev/null @@ -1 +0,0 @@ -org.gradle.console=plain \ No newline at end of file From b8b1f42a14222a1e276f3e30836dc3f5d484e788 Mon Sep 17 00:00:00 2001 From: Giovanni Ciatto Date: Thu, 11 Jun 2020 14:08:33 +0200 Subject: [PATCH 14/20] move support wrappers classes for primitives in it.unibo.tuprolog.solve.primitive --- .../kotlin/it/unibo/tuprolog/solve/stdlib/primitive/Throw.kt | 1 + .../solve/{stdlib => }/primitive/ArithmeticRelation.kt | 2 +- .../solve/{stdlib => }/primitive/BacktrackableSideEffect0.kt | 2 +- .../solve/{stdlib => }/primitive/BacktrackableSideEffect1.kt | 2 +- .../tuprolog/solve/{stdlib => }/primitive/BinaryRelation.kt | 3 +-- .../{stdlib => }/primitive/NonBacktrackableTernaryRelation.kt | 3 +-- .../solve/{stdlib => }/primitive/PredicateWithoutArguments.kt | 3 +-- .../unibo/tuprolog/solve/{stdlib => }/primitive/SideEffect0.kt | 2 +- .../unibo/tuprolog/solve/{stdlib => }/primitive/SideEffect1.kt | 2 +- .../tuprolog/solve/{stdlib => }/primitive/TermRelation.kt | 2 +- .../tuprolog/solve/{stdlib => }/primitive/TernaryRelation.kt | 3 +-- .../unibo/tuprolog/solve/{stdlib => }/primitive/TypeEnsurer.kt | 3 +-- .../unibo/tuprolog/solve/{stdlib => }/primitive/TypeTester.kt | 2 +- .../tuprolog/solve/{stdlib => }/primitive/UnaryPredicate.kt | 3 +-- .../it/unibo/tuprolog/solve/primitive/ZeroaryPredicate.kt | 3 +++ .../it/unibo/tuprolog/solve/stdlib/primitive/AbstractAssert.kt | 1 + .../unibo/tuprolog/solve/stdlib/primitive/ArithmeticEqual.kt | 1 + .../tuprolog/solve/stdlib/primitive/ArithmeticGreaterThan.kt | 1 + .../solve/stdlib/primitive/ArithmeticGreaterThanOrEqualTo.kt | 1 + .../tuprolog/solve/stdlib/primitive/ArithmeticLowerThan.kt | 1 + .../solve/stdlib/primitive/ArithmeticLowerThanOrEqualTo.kt | 1 + .../tuprolog/solve/stdlib/primitive/ArithmeticNotEqual.kt | 1 + .../kotlin/it/unibo/tuprolog/solve/stdlib/primitive/Atom.kt | 1 + .../kotlin/it/unibo/tuprolog/solve/stdlib/primitive/Atomic.kt | 1 + .../it/unibo/tuprolog/solve/stdlib/primitive/Callable.kt | 1 + .../it/unibo/tuprolog/solve/stdlib/primitive/Compound.kt | 1 + .../unibo/tuprolog/solve/stdlib/primitive/EnsureExecutable.kt | 1 + .../kotlin/it/unibo/tuprolog/solve/stdlib/primitive/FindAll.kt | 1 + .../kotlin/it/unibo/tuprolog/solve/stdlib/primitive/Float.kt | 1 + .../kotlin/it/unibo/tuprolog/solve/stdlib/primitive/Ground.kt | 1 + .../kotlin/it/unibo/tuprolog/solve/stdlib/primitive/Integer.kt | 1 + .../kotlin/it/unibo/tuprolog/solve/stdlib/primitive/Is.kt | 1 + .../kotlin/it/unibo/tuprolog/solve/stdlib/primitive/Natural.kt | 1 + .../kotlin/it/unibo/tuprolog/solve/stdlib/primitive/NewLine.kt | 1 + .../kotlin/it/unibo/tuprolog/solve/stdlib/primitive/NonVar.kt | 1 + .../unibo/tuprolog/solve/stdlib/primitive/NotUnifiableWith.kt | 1 + .../kotlin/it/unibo/tuprolog/solve/stdlib/primitive/Number.kt | 1 + .../kotlin/it/unibo/tuprolog/solve/stdlib/primitive/Retract.kt | 1 + .../it/unibo/tuprolog/solve/stdlib/primitive/TermIdentical.kt | 1 + .../unibo/tuprolog/solve/stdlib/primitive/TermNotIdentical.kt | 1 + .../it/unibo/tuprolog/solve/stdlib/primitive/UnifiesWith.kt | 1 + .../kotlin/it/unibo/tuprolog/solve/stdlib/primitive/Var.kt | 1 + .../kotlin/it/unibo/tuprolog/solve/stdlib/primitive/Write.kt | 1 + .../solve/stdlib/primitive/TypeTestingPrimitivesTest.kt | 1 + .../solve/stdlib/primitive/testutils/ArithmeticUtils.kt | 1 + .../solve/stdlib/primitive/testutils/TypeTestingUtils.kt | 1 + 46 files changed, 48 insertions(+), 19 deletions(-) rename solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/{stdlib => }/primitive/ArithmeticRelation.kt (95%) rename solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/{stdlib => }/primitive/BacktrackableSideEffect0.kt (94%) rename solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/{stdlib => }/primitive/BacktrackableSideEffect1.kt (94%) rename solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/{stdlib => }/primitive/BinaryRelation.kt (90%) rename solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/{stdlib => }/primitive/NonBacktrackableTernaryRelation.kt (85%) rename solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/{stdlib => }/primitive/PredicateWithoutArguments.kt (68%) rename solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/{stdlib => }/primitive/SideEffect0.kt (94%) rename solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/{stdlib => }/primitive/SideEffect1.kt (95%) rename solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/{stdlib => }/primitive/TermRelation.kt (96%) rename solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/{stdlib => }/primitive/TernaryRelation.kt (87%) rename solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/{stdlib => }/primitive/TypeEnsurer.kt (82%) rename solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/{stdlib => }/primitive/TypeTester.kt (94%) rename solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/{stdlib => }/primitive/UnaryPredicate.kt (66%) create mode 100644 solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/ZeroaryPredicate.kt diff --git a/solve-classic/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/Throw.kt b/solve-classic/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/Throw.kt index 80196c933..d5073220f 100644 --- a/solve-classic/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/Throw.kt +++ b/solve-classic/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/Throw.kt @@ -7,6 +7,7 @@ import it.unibo.tuprolog.solve.Solve import it.unibo.tuprolog.solve.exception.PrologError import it.unibo.tuprolog.solve.exception.TuPrologRuntimeException import it.unibo.tuprolog.solve.exception.error.MessageError +import it.unibo.tuprolog.solve.primitive.UnaryPredicate object Throw : UnaryPredicate("throw") { override fun uncheckedImplementation(request: Solve.Request): Sequence = diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/ArithmeticRelation.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/ArithmeticRelation.kt similarity index 95% rename from solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/ArithmeticRelation.kt rename to solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/ArithmeticRelation.kt index 4131b8c1e..d63bf284f 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/ArithmeticRelation.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/ArithmeticRelation.kt @@ -1,4 +1,4 @@ -package it.unibo.tuprolog.solve.stdlib.primitive +package it.unibo.tuprolog.solve.primitive import it.unibo.tuprolog.core.Numeric import it.unibo.tuprolog.core.Term diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/BacktrackableSideEffect0.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/BacktrackableSideEffect0.kt similarity index 94% rename from solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/BacktrackableSideEffect0.kt rename to solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/BacktrackableSideEffect0.kt index bed26d56d..6f9902632 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/BacktrackableSideEffect0.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/BacktrackableSideEffect0.kt @@ -1,4 +1,4 @@ -package it.unibo.tuprolog.solve.stdlib.primitive +package it.unibo.tuprolog.solve.primitive import it.unibo.tuprolog.solve.ExecutionContext import it.unibo.tuprolog.solve.Solve diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/BacktrackableSideEffect1.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/BacktrackableSideEffect1.kt similarity index 94% rename from solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/BacktrackableSideEffect1.kt rename to solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/BacktrackableSideEffect1.kt index 9b60693a0..48b03c984 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/BacktrackableSideEffect1.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/BacktrackableSideEffect1.kt @@ -1,4 +1,4 @@ -package it.unibo.tuprolog.solve.stdlib.primitive +package it.unibo.tuprolog.solve.primitive import it.unibo.tuprolog.core.Term import it.unibo.tuprolog.solve.ExecutionContext diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/BinaryRelation.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/BinaryRelation.kt similarity index 90% rename from solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/BinaryRelation.kt rename to solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/BinaryRelation.kt index 589c1310f..082a03e47 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/BinaryRelation.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/BinaryRelation.kt @@ -1,10 +1,9 @@ -package it.unibo.tuprolog.solve.stdlib.primitive +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 -import it.unibo.tuprolog.solve.primitive.PrimitiveWrapper /** Base class to implement primitives that relate two [Term]s and provide a single response */ abstract class BinaryRelation(operator: String) : PrimitiveWrapper(operator, 2) { diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/NonBacktrackableTernaryRelation.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/NonBacktrackableTernaryRelation.kt similarity index 85% rename from solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/NonBacktrackableTernaryRelation.kt rename to solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/NonBacktrackableTernaryRelation.kt index fd50a4121..ec3db2ea6 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/NonBacktrackableTernaryRelation.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/NonBacktrackableTernaryRelation.kt @@ -1,9 +1,8 @@ -package it.unibo.tuprolog.solve.stdlib.primitive +package it.unibo.tuprolog.solve.primitive import it.unibo.tuprolog.core.Term import it.unibo.tuprolog.solve.ExecutionContext import it.unibo.tuprolog.solve.Solve -import it.unibo.tuprolog.solve.primitive.PrimitiveWrapper /** Base class to implement primitives that relate tree [Term]s and are not back-trackable */ abstract class NonBacktrackableTernaryRelation(operator: String) : TernaryRelation(operator) { diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/PredicateWithoutArguments.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/PredicateWithoutArguments.kt similarity index 68% rename from solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/PredicateWithoutArguments.kt rename to solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/PredicateWithoutArguments.kt index f4fe9eb81..b9df38cce 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/PredicateWithoutArguments.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/PredicateWithoutArguments.kt @@ -1,7 +1,6 @@ -package it.unibo.tuprolog.solve.stdlib.primitive +package it.unibo.tuprolog.solve.primitive import it.unibo.tuprolog.solve.ExecutionContext -import it.unibo.tuprolog.solve.primitive.PrimitiveWrapper /** A base class to implement predicates with zero argument */ abstract class PredicateWithoutArguments(operator: String) : PrimitiveWrapper(operator, 0) diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/SideEffect0.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/SideEffect0.kt similarity index 94% rename from solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/SideEffect0.kt rename to solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/SideEffect0.kt index f772c8f10..982d0b6e1 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/SideEffect0.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/SideEffect0.kt @@ -1,4 +1,4 @@ -package it.unibo.tuprolog.solve.stdlib.primitive +package it.unibo.tuprolog.solve.primitive import it.unibo.tuprolog.solve.ExecutionContext import it.unibo.tuprolog.solve.Solve diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/SideEffect1.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/SideEffect1.kt similarity index 95% rename from solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/SideEffect1.kt rename to solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/SideEffect1.kt index 94362f161..f9fedeefa 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/SideEffect1.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/SideEffect1.kt @@ -1,4 +1,4 @@ -package it.unibo.tuprolog.solve.stdlib.primitive +package it.unibo.tuprolog.solve.primitive import it.unibo.tuprolog.core.Term import it.unibo.tuprolog.solve.ExecutionContext diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/TermRelation.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/TermRelation.kt similarity index 96% rename from solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/TermRelation.kt rename to solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/TermRelation.kt index c2fd6be9e..faad78d9c 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/TermRelation.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/TermRelation.kt @@ -1,4 +1,4 @@ -package it.unibo.tuprolog.solve.stdlib.primitive +package it.unibo.tuprolog.solve.primitive import it.unibo.tuprolog.core.Substitution import it.unibo.tuprolog.core.Term diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/TernaryRelation.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/TernaryRelation.kt similarity index 87% rename from solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/TernaryRelation.kt rename to solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/TernaryRelation.kt index 36b6a978e..d8153f625 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/TernaryRelation.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/TernaryRelation.kt @@ -1,9 +1,8 @@ -package it.unibo.tuprolog.solve.stdlib.primitive +package it.unibo.tuprolog.solve.primitive import it.unibo.tuprolog.core.Term import it.unibo.tuprolog.solve.ExecutionContext import it.unibo.tuprolog.solve.Solve -import it.unibo.tuprolog.solve.primitive.PrimitiveWrapper /** Base class to implement primitives that relate tree [Term]s */ abstract class TernaryRelation(operator: String) : PrimitiveWrapper(operator, 3) { diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/TypeEnsurer.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/TypeEnsurer.kt similarity index 82% rename from solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/TypeEnsurer.kt rename to solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/TypeEnsurer.kt index 970fd22d9..ecfbd4316 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/TypeEnsurer.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/TypeEnsurer.kt @@ -1,9 +1,8 @@ -package it.unibo.tuprolog.solve.stdlib.primitive +package it.unibo.tuprolog.solve.primitive import it.unibo.tuprolog.core.Term import it.unibo.tuprolog.solve.ExecutionContext import it.unibo.tuprolog.solve.Solve -import it.unibo.tuprolog.solve.exception.TuPrologRuntimeException abstract class TypeEnsurer(typeName: String) : UnaryPredicate(typeName) { override fun uncheckedImplementation(request: Solve.Request): Sequence = sequence { diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/TypeTester.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/TypeTester.kt similarity index 94% rename from solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/TypeTester.kt rename to solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/TypeTester.kt index b319ce4a4..4bebe4f88 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/TypeTester.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/TypeTester.kt @@ -1,4 +1,4 @@ -package it.unibo.tuprolog.solve.stdlib.primitive +package it.unibo.tuprolog.solve.primitive import it.unibo.tuprolog.core.Term import it.unibo.tuprolog.solve.ExecutionContext diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/UnaryPredicate.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/UnaryPredicate.kt similarity index 66% rename from solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/UnaryPredicate.kt rename to solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/UnaryPredicate.kt index 888bcb2f7..61a7622b7 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/UnaryPredicate.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/UnaryPredicate.kt @@ -1,7 +1,6 @@ -package it.unibo.tuprolog.solve.stdlib.primitive +package it.unibo.tuprolog.solve.primitive import it.unibo.tuprolog.solve.ExecutionContext -import it.unibo.tuprolog.solve.primitive.PrimitiveWrapper /** A base class to implement predicates with one argument */ abstract class UnaryPredicate(operator: String) : PrimitiveWrapper(operator, 1) diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/ZeroaryPredicate.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/ZeroaryPredicate.kt new file mode 100644 index 000000000..5358d1bfd --- /dev/null +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/ZeroaryPredicate.kt @@ -0,0 +1,3 @@ +package it.unibo.tuprolog.solve.primitive + +typealias ZeroaryPredicate = PredicateWithoutArguments \ No newline at end of file diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/AbstractAssert.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/AbstractAssert.kt index 5175a55b6..0d419f530 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/AbstractAssert.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/AbstractAssert.kt @@ -6,6 +6,7 @@ import it.unibo.tuprolog.core.Struct import it.unibo.tuprolog.core.Term import it.unibo.tuprolog.solve.ExecutionContext import it.unibo.tuprolog.solve.Solve +import it.unibo.tuprolog.solve.primitive.SideEffect1 abstract class AbstractAssert(suffix: String, private val before: Boolean) : SideEffect1("assert$suffix") { override fun accept(request: Solve.Request, term: Term): Solve.Response = diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/ArithmeticEqual.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/ArithmeticEqual.kt index 77cd34d81..b4f68dca4 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/ArithmeticEqual.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/ArithmeticEqual.kt @@ -2,6 +2,7 @@ package it.unibo.tuprolog.solve.stdlib.primitive import it.unibo.tuprolog.core.Numeric import it.unibo.tuprolog.solve.ExecutionContext +import it.unibo.tuprolog.solve.primitive.ArithmeticRelation /** Implementation of '=:='/2 predicate */ object ArithmeticEqual : ArithmeticRelation("=:=") { diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/ArithmeticGreaterThan.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/ArithmeticGreaterThan.kt index 5486f71b5..23c708f0e 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/ArithmeticGreaterThan.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/ArithmeticGreaterThan.kt @@ -2,6 +2,7 @@ package it.unibo.tuprolog.solve.stdlib.primitive import it.unibo.tuprolog.core.Numeric import it.unibo.tuprolog.solve.ExecutionContext +import it.unibo.tuprolog.solve.primitive.ArithmeticRelation /** Implementation of '>'/2 predicate */ object ArithmeticGreaterThan : ArithmeticRelation(">") { diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/ArithmeticGreaterThanOrEqualTo.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/ArithmeticGreaterThanOrEqualTo.kt index de0210353..7971a8340 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/ArithmeticGreaterThanOrEqualTo.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/ArithmeticGreaterThanOrEqualTo.kt @@ -2,6 +2,7 @@ package it.unibo.tuprolog.solve.stdlib.primitive import it.unibo.tuprolog.core.Numeric import it.unibo.tuprolog.solve.ExecutionContext +import it.unibo.tuprolog.solve.primitive.ArithmeticRelation /** Implementation of '>='/2 predicate */ object ArithmeticGreaterThanOrEqualTo : ArithmeticRelation(">=") { diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/ArithmeticLowerThan.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/ArithmeticLowerThan.kt index e4d3062ef..4b9b2ef6e 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/ArithmeticLowerThan.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/ArithmeticLowerThan.kt @@ -2,6 +2,7 @@ package it.unibo.tuprolog.solve.stdlib.primitive import it.unibo.tuprolog.core.Numeric import it.unibo.tuprolog.solve.ExecutionContext +import it.unibo.tuprolog.solve.primitive.ArithmeticRelation /** Implementation of '<'/2 predicate */ object ArithmeticLowerThan : ArithmeticRelation("<") { diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/ArithmeticLowerThanOrEqualTo.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/ArithmeticLowerThanOrEqualTo.kt index d42470c34..3ebb7dc2a 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/ArithmeticLowerThanOrEqualTo.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/ArithmeticLowerThanOrEqualTo.kt @@ -2,6 +2,7 @@ package it.unibo.tuprolog.solve.stdlib.primitive import it.unibo.tuprolog.core.Numeric import it.unibo.tuprolog.solve.ExecutionContext +import it.unibo.tuprolog.solve.primitive.ArithmeticRelation /** Implementation of '=<'/2 predicate */ object ArithmeticLowerThanOrEqualTo : ArithmeticRelation("=<") { diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/ArithmeticNotEqual.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/ArithmeticNotEqual.kt index 44f2cf544..0ead36832 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/ArithmeticNotEqual.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/ArithmeticNotEqual.kt @@ -2,6 +2,7 @@ package it.unibo.tuprolog.solve.stdlib.primitive import it.unibo.tuprolog.core.Numeric import it.unibo.tuprolog.solve.ExecutionContext +import it.unibo.tuprolog.solve.primitive.ArithmeticRelation /** Implementation of '=\='/2 predicate */ object ArithmeticNotEqual : ArithmeticRelation("=\\=") { diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/Atom.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/Atom.kt index 27196b4b5..1ca808412 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/Atom.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/Atom.kt @@ -2,6 +2,7 @@ package it.unibo.tuprolog.solve.stdlib.primitive import it.unibo.tuprolog.core.Term import it.unibo.tuprolog.solve.ExecutionContext +import it.unibo.tuprolog.solve.primitive.TypeTester object Atom : TypeTester("atom") { override fun testType(term: Term): Boolean = term is it.unibo.tuprolog.core.Atom diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/Atomic.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/Atomic.kt index ec1c077a6..c476392ac 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/Atomic.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/Atomic.kt @@ -3,6 +3,7 @@ package it.unibo.tuprolog.solve.stdlib.primitive import it.unibo.tuprolog.core.Constant import it.unibo.tuprolog.core.Term import it.unibo.tuprolog.solve.ExecutionContext +import it.unibo.tuprolog.solve.primitive.TypeTester object Atomic : TypeTester("atomic") { override fun testType(term: Term): Boolean = term is Constant diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/Callable.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/Callable.kt index 474067796..e356bf1b4 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/Callable.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/Callable.kt @@ -3,6 +3,7 @@ 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.primitive.TypeTester object Callable : TypeTester("callable") { override fun testType(term: Term): Boolean = term is Struct diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/Compound.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/Compound.kt index 11b910d1b..65be57249 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/Compound.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/Compound.kt @@ -3,6 +3,7 @@ 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.primitive.TypeTester object Compound : TypeTester("compound") { override fun testType(term: Term): Boolean = diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/EnsureExecutable.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/EnsureExecutable.kt index 4b318a4b3..62a3b133e 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/EnsureExecutable.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/EnsureExecutable.kt @@ -7,6 +7,7 @@ import it.unibo.tuprolog.solve.Signature import it.unibo.tuprolog.solve.exception.error.InstantiationError import it.unibo.tuprolog.solve.exception.error.TypeError import it.unibo.tuprolog.solve.extractSignature +import it.unibo.tuprolog.solve.primitive.TypeEnsurer object EnsureExecutable : TypeEnsurer("ensure_executable") { private fun ensurerVisitor(context: ExecutionContext, procedure: Signature): TermVisitor = diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/FindAll.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/FindAll.kt index cdb27fa81..a7b42336e 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/FindAll.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/FindAll.kt @@ -8,6 +8,7 @@ import it.unibo.tuprolog.solve.ExecutionContext import it.unibo.tuprolog.solve.Solution import it.unibo.tuprolog.solve.Solve import it.unibo.tuprolog.solve.exception.error.MetaError +import it.unibo.tuprolog.solve.primitive.NonBacktrackableTernaryRelation import it.unibo.tuprolog.unify.Unificator.Companion.mguWith object FindAll : NonBacktrackableTernaryRelation("findall") { diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/Float.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/Float.kt index 18a7ff7ff..65067d1a3 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/Float.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/Float.kt @@ -3,6 +3,7 @@ package it.unibo.tuprolog.solve.stdlib.primitive import it.unibo.tuprolog.core.Real import it.unibo.tuprolog.core.Term import it.unibo.tuprolog.solve.ExecutionContext +import it.unibo.tuprolog.solve.primitive.TypeTester object Float : TypeTester("float") { override fun testType(term: Term): Boolean = term is Real diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/Ground.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/Ground.kt index b3b84c5c5..ccda28eab 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/Ground.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/Ground.kt @@ -2,6 +2,7 @@ package it.unibo.tuprolog.solve.stdlib.primitive import it.unibo.tuprolog.core.Term import it.unibo.tuprolog.solve.ExecutionContext +import it.unibo.tuprolog.solve.primitive.TypeTester object Ground : TypeTester("ground") { override fun testType(term: Term): Boolean = term.isGround diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/Integer.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/Integer.kt index 083326c54..a51144a97 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/Integer.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/Integer.kt @@ -2,6 +2,7 @@ package it.unibo.tuprolog.solve.stdlib.primitive import it.unibo.tuprolog.core.Term import it.unibo.tuprolog.solve.ExecutionContext +import it.unibo.tuprolog.solve.primitive.TypeTester object Integer : TypeTester("integer") { override fun testType(term: Term): Boolean = term is it.unibo.tuprolog.core.Integer diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/Is.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/Is.kt index 540a66f63..57b7ebd2f 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/Is.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/Is.kt @@ -5,6 +5,7 @@ import it.unibo.tuprolog.core.Term import it.unibo.tuprolog.solve.ExecutionContext import it.unibo.tuprolog.solve.Solve import it.unibo.tuprolog.solve.function.ArithmeticEvaluator +import it.unibo.tuprolog.solve.primitive.TermRelation import it.unibo.tuprolog.unify.Unificator.Companion.mguWith /** diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/Natural.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/Natural.kt index da4b5ab44..7582498c8 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/Natural.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/Natural.kt @@ -6,6 +6,7 @@ import it.unibo.tuprolog.core.Term import it.unibo.tuprolog.core.Var import it.unibo.tuprolog.solve.ExecutionContext import it.unibo.tuprolog.solve.Solve +import it.unibo.tuprolog.solve.primitive.UnaryPredicate import org.gciatto.kt.math.BigInteger // TODO doc diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/NewLine.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/NewLine.kt index c7e8f8545..d4b433725 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/NewLine.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/NewLine.kt @@ -2,6 +2,7 @@ package it.unibo.tuprolog.solve.stdlib.primitive import it.unibo.tuprolog.solve.ExecutionContext import it.unibo.tuprolog.solve.Solve +import it.unibo.tuprolog.solve.primitive.SideEffect0 object NewLine : SideEffect0("nl") { override fun accept(request: Solve.Request): Solve.Response { diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/NonVar.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/NonVar.kt index 10364a512..9932a19c5 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/NonVar.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/NonVar.kt @@ -2,6 +2,7 @@ package it.unibo.tuprolog.solve.stdlib.primitive import it.unibo.tuprolog.core.Term import it.unibo.tuprolog.solve.ExecutionContext +import it.unibo.tuprolog.solve.primitive.TypeTester object NonVar : TypeTester("nonvar") { override fun testType(term: Term): Boolean = term !is it.unibo.tuprolog.core.Var diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/NotUnifiableWith.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/NotUnifiableWith.kt index 028118791..e2152da09 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/NotUnifiableWith.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/NotUnifiableWith.kt @@ -2,6 +2,7 @@ package it.unibo.tuprolog.solve.stdlib.primitive import it.unibo.tuprolog.core.Term import it.unibo.tuprolog.solve.ExecutionContext +import it.unibo.tuprolog.solve.primitive.TermRelation import it.unibo.tuprolog.unify.Unificator.Companion.matches /** Implementation of '\='/2 predicate */ diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/Number.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/Number.kt index e4e112330..f5829ef45 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/Number.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/Number.kt @@ -3,6 +3,7 @@ package it.unibo.tuprolog.solve.stdlib.primitive import it.unibo.tuprolog.core.Numeric import it.unibo.tuprolog.core.Term import it.unibo.tuprolog.solve.ExecutionContext +import it.unibo.tuprolog.solve.primitive.TypeTester object Number : TypeTester("number") { override fun testType(term: Term): Boolean = term is Numeric diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/Retract.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/Retract.kt index dabf7c61a..6584101df 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/Retract.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/Retract.kt @@ -4,6 +4,7 @@ import it.unibo.tuprolog.core.* import it.unibo.tuprolog.core.Var import it.unibo.tuprolog.solve.ExecutionContext import it.unibo.tuprolog.solve.Solve +import it.unibo.tuprolog.solve.primitive.BacktrackableSideEffect1 import it.unibo.tuprolog.theory.RetractResult import it.unibo.tuprolog.unify.Unificator.Companion.mguWith diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/TermIdentical.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/TermIdentical.kt index e58522320..e9e4b8f4e 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/TermIdentical.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/TermIdentical.kt @@ -2,6 +2,7 @@ package it.unibo.tuprolog.solve.stdlib.primitive import it.unibo.tuprolog.core.Term import it.unibo.tuprolog.solve.ExecutionContext +import it.unibo.tuprolog.solve.primitive.TermRelation /** Implementation of '=='/2 predicate */ object TermIdentical : TermRelation.WithoutSideEffects("==") { diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/TermNotIdentical.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/TermNotIdentical.kt index 19830e562..9c863aadd 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/TermNotIdentical.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/TermNotIdentical.kt @@ -2,6 +2,7 @@ package it.unibo.tuprolog.solve.stdlib.primitive import it.unibo.tuprolog.core.Term import it.unibo.tuprolog.solve.ExecutionContext +import it.unibo.tuprolog.solve.primitive.TermRelation /** Implementation of `'\=='/2` predicate */ object TermNotIdentical : TermRelation.WithoutSideEffects("\\==") { diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/UnifiesWith.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/UnifiesWith.kt index 84035c2ac..55345d67b 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/UnifiesWith.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/UnifiesWith.kt @@ -3,6 +3,7 @@ package it.unibo.tuprolog.solve.stdlib.primitive import it.unibo.tuprolog.core.Substitution import it.unibo.tuprolog.core.Term import it.unibo.tuprolog.solve.ExecutionContext +import it.unibo.tuprolog.solve.primitive.TermRelation import it.unibo.tuprolog.unify.Unificator.Companion.mguWith /** Implementation of '='/2 predicate */ diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/Var.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/Var.kt index ad20a95d9..77dcb1fe4 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/Var.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/Var.kt @@ -2,6 +2,7 @@ package it.unibo.tuprolog.solve.stdlib.primitive import it.unibo.tuprolog.core.Term import it.unibo.tuprolog.solve.ExecutionContext +import it.unibo.tuprolog.solve.primitive.TypeTester object Var : TypeTester("var") { override fun testType(term: Term): Boolean = term is it.unibo.tuprolog.core.Var diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/Write.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/Write.kt index eb7c3c948..7c181cff3 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/Write.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/Write.kt @@ -4,6 +4,7 @@ import it.unibo.tuprolog.core.Atom import it.unibo.tuprolog.core.Term import it.unibo.tuprolog.solve.ExecutionContext import it.unibo.tuprolog.solve.Solve +import it.unibo.tuprolog.solve.primitive.SideEffect1 object Write : SideEffect1("write") { override fun accept(request: Solve.Request, term: Term): Solve.Response { diff --git a/test-solve/src/commonTest/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/TypeTestingPrimitivesTest.kt b/test-solve/src/commonTest/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/TypeTestingPrimitivesTest.kt index 4c0e32f18..e9761b9b7 100644 --- a/test-solve/src/commonTest/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/TypeTestingPrimitivesTest.kt +++ b/test-solve/src/commonTest/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/TypeTestingPrimitivesTest.kt @@ -1,6 +1,7 @@ package it.unibo.tuprolog.solve.stdlib.primitive import it.unibo.tuprolog.solve.Solve +import it.unibo.tuprolog.solve.primitive.UnaryPredicate import it.unibo.tuprolog.solve.stdlib.primitive.testutils.TypeTestingUtils.assertCorrectResponse import it.unibo.tuprolog.solve.stdlib.primitive.testutils.TypeTestingUtils.atomQueryToResult import it.unibo.tuprolog.solve.stdlib.primitive.testutils.TypeTestingUtils.atomicQueryToResult diff --git a/test-solve/src/commonTest/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/testutils/ArithmeticUtils.kt b/test-solve/src/commonTest/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/testutils/ArithmeticUtils.kt index beb03c552..938bb4a88 100644 --- a/test-solve/src/commonTest/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/testutils/ArithmeticUtils.kt +++ b/test-solve/src/commonTest/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/testutils/ArithmeticUtils.kt @@ -10,6 +10,7 @@ import it.unibo.tuprolog.solve.Solve import it.unibo.tuprolog.solve.exception.TuPrologRuntimeException import it.unibo.tuprolog.solve.exception.error.EvaluationError import it.unibo.tuprolog.solve.exception.error.InstantiationError +import it.unibo.tuprolog.solve.primitive.ArithmeticRelation import kotlin.reflect.KClass import kotlin.test.assertFailsWith import kotlin.test.assertTrue diff --git a/test-solve/src/commonTest/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/testutils/TypeTestingUtils.kt b/test-solve/src/commonTest/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/testutils/TypeTestingUtils.kt index 13874ac6f..4627c6ba9 100644 --- a/test-solve/src/commonTest/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/testutils/TypeTestingUtils.kt +++ b/test-solve/src/commonTest/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/testutils/TypeTestingUtils.kt @@ -8,6 +8,7 @@ import it.unibo.tuprolog.solve.Solve import it.unibo.tuprolog.solve.exception.TuPrologRuntimeException import it.unibo.tuprolog.solve.exception.error.InstantiationError import it.unibo.tuprolog.solve.exception.error.TypeError +import it.unibo.tuprolog.solve.primitive.UnaryPredicate import it.unibo.tuprolog.solve.stdlib.primitive.* import it.unibo.tuprolog.utils.squared import kotlin.collections.List From 86a6589fcca4d84231653604eed2aa61995c6e76 Mon Sep 17 00:00:00 2001 From: Giovanni Ciatto Date: Thu, 11 Jun 2020 15:08:58 +0200 Subject: [PATCH 15/20] fix primitive wrappers hierarchy --- .../kotlin/it/unibo/tuprolog/solve/Solve.kt | 29 ++++++++ .../solve/primitive/ArithmeticRelation.kt | 24 ++----- .../primitive/BacktrackableSideEffect0.kt | 20 ------ .../primitive/BacktrackableSideEffect1.kt | 21 ------ .../solve/primitive/BinaryRelation.kt | 58 ++++++++++++++-- .../NonBacktrackableTernaryRelation.kt | 24 ------- .../primitive/PredicateWithoutArguments.kt | 44 +++++++++++- .../tuprolog/solve/primitive/SideEffect0.kt | 21 ------ .../tuprolog/solve/primitive/SideEffect1.kt | 26 ------- .../tuprolog/solve/primitive/TermRelation.kt | 30 --------- .../solve/primitive/TernaryRelation.kt | 67 +++++++++++++++++-- .../tuprolog/solve/primitive/TypeEnsurer.kt | 11 ++- .../tuprolog/solve/primitive/TypeTester.kt | 21 +----- .../solve/primitive/UnaryPredicate.kt | 57 +++++++++++++++- 14 files changed, 256 insertions(+), 197 deletions(-) delete mode 100644 solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/BacktrackableSideEffect0.kt delete mode 100644 solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/BacktrackableSideEffect1.kt delete mode 100644 solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/NonBacktrackableTernaryRelation.kt delete mode 100644 solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/SideEffect0.kt delete mode 100644 solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/SideEffect1.kt delete mode 100644 solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/TermRelation.kt diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/Solve.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/Solve.kt index f98f2ffdd..23f91c629 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/Solve.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/Solve.kt @@ -48,6 +48,35 @@ sealed class Solve { /** Creates a new [Response] to this Request */ @JsName("replyWith") + fun replyWith( + substitution: Substitution, + libraries: Libraries? = null, + flags: PrologFlags? = null, + staticKb: Theory? = null, + dynamicKb: Theory? = null, + sideEffectManager: SideEffectManager? = null, + inputChannels: PrologInputChannels<*>? = null, + outputChannels: PrologOutputChannels<*>? = null + ) = when (substitution) { + is Substitution.Unifier -> { + replySuccess( + substitution, + libraries, + flags, + staticKb, + dynamicKb, + sideEffectManager, + inputChannels, + outputChannels + ) + } + else -> { + replyFail(libraries, flags, staticKb, dynamicKb, sideEffectManager, inputChannels, outputChannels) + } + } + + /** Creates a new [Response] to this Request */ + @JsName("replyWithSolution") fun replyWith( solution: Solution, libraries: Libraries? = null, diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/ArithmeticRelation.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/ArithmeticRelation.kt index d63bf284f..a030e4919 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/ArithmeticRelation.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/ArithmeticRelation.kt @@ -4,25 +4,15 @@ import it.unibo.tuprolog.core.Numeric import it.unibo.tuprolog.core.Term import it.unibo.tuprolog.solve.ExecutionContext import it.unibo.tuprolog.solve.Solve -import it.unibo.tuprolog.solve.function.ArithmeticEvaluator /** Base class for implementing arithmetic relation between [Numeric] terms */ -abstract class ArithmeticRelation(operator: String) : BinaryRelation(operator) { +abstract class ArithmeticRelation(operator: String) : BinaryRelation.Predicative(operator) { - override fun uncheckedImplementation(request: Solve.Request): Sequence = - sequenceOf( - request.ensuringAllArgumentsAreInstantiated() - .computeSingleResponse() - ) + override fun Solve.Request.compute(first: Term, second: Term): Boolean { + ensuringArgumentIsNumeric(1) + ensuringArgumentIsNumeric(2) + return arithmeticRelation(first as Numeric, second as Numeric) + } - override fun Solve.Request.computeSingleResponse(): Solve.Response = - ArithmeticEvaluator(context).let { - replyWith(relationWithoutSideEffects(arguments[0].accept(it), arguments[1].accept(it))) - } - - override fun relationWithoutSideEffects(x: Term, y: Term): Boolean = - arithmeticRelation(x as Numeric, y as Numeric) - - /** Template method that should implement the arithmetic relation between [x] and [y] */ - protected abstract fun arithmeticRelation(x: Numeric, y: Numeric): Boolean + abstract fun arithmeticRelation(x: Numeric, y: Numeric): Boolean } diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/BacktrackableSideEffect0.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/BacktrackableSideEffect0.kt deleted file mode 100644 index 6f9902632..000000000 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/BacktrackableSideEffect0.kt +++ /dev/null @@ -1,20 +0,0 @@ -package it.unibo.tuprolog.solve.primitive - -import it.unibo.tuprolog.solve.ExecutionContext -import it.unibo.tuprolog.solve.Solve - -abstract class BacktrackableSideEffect0(typeName: String) : PredicateWithoutArguments(typeName) { - override fun uncheckedImplementation(request: Solve.Request): Sequence = - accept(request) - - abstract fun accept(request: Solve.Request): Sequence - - companion object { - fun of(typeName: String, consumer: (Solve.Request) -> Sequence): BacktrackableSideEffect0 = - object : BacktrackableSideEffect0(typeName) { - override fun accept(request: Solve.Request): Sequence { - return consumer(request) - } - } - } -} \ No newline at end of file diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/BacktrackableSideEffect1.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/BacktrackableSideEffect1.kt deleted file mode 100644 index 48b03c984..000000000 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/BacktrackableSideEffect1.kt +++ /dev/null @@ -1,21 +0,0 @@ -package it.unibo.tuprolog.solve.primitive - -import it.unibo.tuprolog.core.Term -import it.unibo.tuprolog.solve.ExecutionContext -import it.unibo.tuprolog.solve.Solve - -abstract class BacktrackableSideEffect1(typeName: String) : UnaryPredicate(typeName) { - override fun uncheckedImplementation(request: Solve.Request): Sequence = - accept(request, request.arguments[0][request.context.substitution]) - - abstract fun accept(request: Solve.Request, term: Term): Sequence - - companion object { - fun of(typeName: String, consumer: (Solve.Request, Term) -> Sequence): BacktrackableSideEffect1 = - object : BacktrackableSideEffect1(typeName) { - override fun accept(request: Solve.Request, term: Term): Sequence { - return consumer(request, term) - } - } - } -} \ No newline at end of file diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/BinaryRelation.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/BinaryRelation.kt index 082a03e47..b5ff33a69 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/BinaryRelation.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/BinaryRelation.kt @@ -8,12 +8,58 @@ import it.unibo.tuprolog.solve.Solve /** Base class to implement primitives that relate two [Term]s and provide a single response */ abstract class BinaryRelation(operator: String) : PrimitiveWrapper(operator, 2) { - /** Template method that should compute the response of the [Term] relation application */ - protected abstract fun Solve.Request.computeSingleResponse(): Solve.Response + /** Template method aimed at computing the application of this relation to three [Term]s */ + protected abstract fun Solve.Request.computeAll( + first: Term, + second: Term + ): Sequence - /** Template method that should be implemented and called in BinaryRelations without side effects */ - protected open fun relationWithoutSideEffects(x: Term, y: Term): Boolean = throw NotImplementedError() + final override fun uncheckedImplementation(request: Solve.Request): Sequence { + return request.computeAll(request.arguments[0], request.arguments[1]) + } - /** Template method that should be implemented and called in BinaryRelations with side effects */ - protected open fun relationWithSideEffects(x: Term, y: Term): Substitution = throw NotImplementedError() + abstract class WithoutSideEffects(operator: String) : BinaryRelation(operator) { + protected abstract fun Solve.Request.computeAllSubstitutions( + first: Term, + second: Term + ): Sequence + + final override fun Solve.Request.computeAll(first: Term, second: Term): Sequence { + return computeAllSubstitutions(first, second).map { replyWith(it) } + } + } + + abstract class NonBacktrackable(operator: String) : BinaryRelation(operator) { + protected abstract fun Solve.Request.computeOne( + first: Term, + second: Term + ): Solve.Response + + final override fun Solve.Request.computeAll(first: Term, second: Term): Sequence { + return sequenceOf(computeOne(first, second)) + } + + } + + abstract class Functional(operator: String) : NonBacktrackable(operator) { + protected abstract fun Solve.Request.computeOneSubstitution( + first: Term, + second: Term + ): Substitution + + final override fun Solve.Request.computeOne(first: Term, second: Term): Solve.Response { + return replyWith(computeOneSubstitution(first, second)) + } + } + + abstract class Predicative(operator: String) : NonBacktrackable(operator) { + protected abstract fun Solve.Request.compute( + first: Term, + second: Term + ): Boolean + + final override fun Solve.Request.computeOne(first: Term, second: Term): Solve.Response { + return if (compute(first, second)) replySuccess() else replyFail() + } + } } diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/NonBacktrackableTernaryRelation.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/NonBacktrackableTernaryRelation.kt deleted file mode 100644 index ec3db2ea6..000000000 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/NonBacktrackableTernaryRelation.kt +++ /dev/null @@ -1,24 +0,0 @@ -package it.unibo.tuprolog.solve.primitive - -import it.unibo.tuprolog.core.Term -import it.unibo.tuprolog.solve.ExecutionContext -import it.unibo.tuprolog.solve.Solve - -/** Base class to implement primitives that relate tree [Term]s and are not back-trackable */ -abstract class NonBacktrackableTernaryRelation(operator: String) : TernaryRelation(operator) { - - override fun Solve.Request.computeAll( - x: Term, - y: Term, - z: Term - ): Sequence { - return sequenceOf(computeOne(x, y, z)) - } - - protected abstract fun Solve.Request.computeOne( - x: Term, - y: Term, - z: Term - ): Solve.Response - -} diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/PredicateWithoutArguments.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/PredicateWithoutArguments.kt index b9df38cce..64bd7a76c 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/PredicateWithoutArguments.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/PredicateWithoutArguments.kt @@ -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(operator: String) : PrimitiveWrapper(operator, 0) +abstract class PredicateWithoutArguments(operator: String) : PrimitiveWrapper(operator, 0) { + /** Template method that should compute the response of the application of this predicate to a term [Term] */ + protected abstract fun Solve.Request.computeAll(): Sequence + + final override fun uncheckedImplementation(request: Solve.Request): Sequence { + return request.computeAll() + } + + abstract class WithoutSideEffects(operator: String) : PredicateWithoutArguments(operator) { + protected abstract fun Solve.Request.computeAllSubstitutions(): Sequence + + final override fun Solve.Request.computeAll(): Sequence { + return computeAllSubstitutions().map { replyWith(it) } + } + } + + abstract class NonBacktrackable(operator: String) : PredicateWithoutArguments(operator) { + protected abstract fun Solve.Request.computeOne(): Solve.Response + + final override fun Solve.Request.computeAll(): Sequence { + return sequenceOf(computeOne()) + } + } + + abstract class Functional(operator: String) : NonBacktrackable(operator) { + protected abstract fun Solve.Request.computeOneSubstitution(): Substitution + + final override fun Solve.Request.computeOne(): Solve.Response { + return replyWith(computeOneSubstitution()) + } + } + + abstract class Predicative(operator: String) : NonBacktrackable(operator) { + protected abstract fun Solve.Request.compute(): Boolean + + final override fun Solve.Request.computeOne(): Solve.Response { + return if (compute()) replySuccess() else replyFail() + } + } +} diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/SideEffect0.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/SideEffect0.kt deleted file mode 100644 index 982d0b6e1..000000000 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/SideEffect0.kt +++ /dev/null @@ -1,21 +0,0 @@ -package it.unibo.tuprolog.solve.primitive - -import it.unibo.tuprolog.solve.ExecutionContext -import it.unibo.tuprolog.solve.Solve - -abstract class SideEffect0(typeName: String) : PredicateWithoutArguments(typeName) { - override fun uncheckedImplementation(request: Solve.Request): Sequence = sequence { - yield(accept(request)) - } - - abstract fun accept(request: Solve.Request): Solve.Response - - companion object { - fun of(typeName: String, consumer: (Solve.Request) -> Solve.Response): SideEffect0 = - object : SideEffect0(typeName) { - override fun accept(request: Solve.Request): Solve.Response { - return consumer(request) - } - } - } -} \ No newline at end of file diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/SideEffect1.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/SideEffect1.kt deleted file mode 100644 index f9fedeefa..000000000 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/SideEffect1.kt +++ /dev/null @@ -1,26 +0,0 @@ -package it.unibo.tuprolog.solve.primitive - -import it.unibo.tuprolog.core.Term -import it.unibo.tuprolog.solve.ExecutionContext -import it.unibo.tuprolog.solve.Solve - -abstract class SideEffect1(typeName: String) : UnaryPredicate(typeName) { - override fun uncheckedImplementation(request: Solve.Request): Sequence = sequence { - yield( - with(request) { - accept(request, arguments[0][context.substitution]) - } - ) - } - - abstract fun accept(request: Solve.Request, term: Term): Solve.Response - - companion object { - fun of(typeName: String, consumer: (Solve.Request, Term) -> Solve.Response): SideEffect1 = - object : SideEffect1(typeName) { - override fun accept(request: Solve.Request, term: Term): Solve.Response { - return consumer(request, term) - } - } - } -} \ No newline at end of file diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/TermRelation.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/TermRelation.kt deleted file mode 100644 index faad78d9c..000000000 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/TermRelation.kt +++ /dev/null @@ -1,30 +0,0 @@ -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 - -/** Base class for implementing relation between possibly not instantiated [Term]s */ -abstract class TermRelation(operator: String) : BinaryRelation(operator) { - - override fun uncheckedImplementation(request: Solve.Request): Sequence = - sequenceOf(request.computeSingleResponse()) - - /** Base class for implementing a relation *without side effects* between [Term]s */ - abstract class WithoutSideEffects(operator: String) : TermRelation(operator) { - - override fun Solve.Request.computeSingleResponse(): Solve.Response = - replyWith(relationWithoutSideEffects(arguments[0], arguments[1])) - } - - /** Base class for implementing a relation *with side effects* between [Term]s */ - abstract class WithSideEffects(operator: String) : TermRelation(operator) { - - override fun Solve.Request.computeSingleResponse(): Solve.Response = - when (val effects: Substitution = relationWithSideEffects(arguments[0], arguments[1])) { - is Substitution.Unifier -> replySuccess(effects) - else -> replyFail() - } - } -} diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/TernaryRelation.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/TernaryRelation.kt index d8153f625..c9e0fa3d1 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/TernaryRelation.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/TernaryRelation.kt @@ -1,5 +1,6 @@ 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 @@ -7,14 +8,70 @@ import it.unibo.tuprolog.solve.Solve /** Base class to implement primitives that relate tree [Term]s */ abstract class TernaryRelation(operator: String) : PrimitiveWrapper(operator, 3) { - /** Template method that should compute the response of the [Term] relation application */ + /** Template method aimed at computing the application of this relation to three [Term]s */ protected abstract fun Solve.Request.computeAll( - x: Term, - y: Term, - z: Term + first: Term, + second: Term, + third: Term ): Sequence - override fun uncheckedImplementation(request: Solve.Request): Sequence { + final override fun uncheckedImplementation(request: Solve.Request): Sequence { return request.computeAll(request.arguments[0], request.arguments[1], request.arguments[2]) } + + abstract class WithoutSideEffects(operator: String) : TernaryRelation(operator) { + protected abstract fun Solve.Request.computeAllSubstitutions( + first: Term, + second: Term, + third: Term + ): Sequence + + final override fun Solve.Request.computeAll( + first: Term, + second: Term, + third: Term + ): Sequence { + return computeAllSubstitutions(first, second, third).map { replyWith(it) } + } + } + + abstract class NonBacktrackable(operator: String) : TernaryRelation(operator) { + protected abstract fun Solve.Request.computeOne( + first: Term, + second: Term, + third: Term + ): Solve.Response + + final override fun Solve.Request.computeAll( + first: Term, + second: Term, + third: Term + ): Sequence { + return sequenceOf(computeOne(first, second, third)) + } + } + + abstract class Functional(operator: String) : NonBacktrackable(operator) { + protected abstract fun Solve.Request.computeOneSubstitution( + first: Term, + second: Term, + third: Term + ): Substitution + + final override fun Solve.Request.computeOne(first: Term, second: Term, third: Term): Solve.Response { + return replyWith(computeOneSubstitution(first, second, third)) + } + } + + abstract class Predicative(operator: String) : NonBacktrackable(operator) { + protected abstract fun Solve.Request.compute( + first: Term, + second: Term, + third: Term + ): Boolean + + final override fun Solve.Request.computeOne(first: Term, second: Term, third: Term): Solve.Response { + return if (compute(first, second, third)) replySuccess() else replyFail() + } + } } diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/TypeEnsurer.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/TypeEnsurer.kt index ecfbd4316..6fceee20a 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/TypeEnsurer.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/TypeEnsurer.kt @@ -4,14 +4,11 @@ import it.unibo.tuprolog.core.Term import it.unibo.tuprolog.solve.ExecutionContext import it.unibo.tuprolog.solve.Solve -abstract class TypeEnsurer(typeName: String) : UnaryPredicate(typeName) { - override fun uncheckedImplementation(request: Solve.Request): Sequence = sequence { - with (request) { - ensureType(context, arguments[0][context.substitution]) - yield(replySuccess()) - } +abstract class TypeEnsurer(typeName: String) : UnaryPredicate.Predicative(typeName) { + override fun Solve.Request.compute(first: Term): Boolean { + ensureType(context, arguments[0][context.substitution]) + return true } abstract fun ensureType(context: E, term: Term) - } \ No newline at end of file diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/TypeTester.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/TypeTester.kt index 4bebe4f88..f99cb6bba 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/TypeTester.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/TypeTester.kt @@ -4,25 +4,10 @@ import it.unibo.tuprolog.core.Term import it.unibo.tuprolog.solve.ExecutionContext import it.unibo.tuprolog.solve.Solve -abstract class TypeTester(typeName: String) : UnaryPredicate(typeName) { - override fun uncheckedImplementation(request: Solve.Request): Sequence = sequence { - yield( - with(request) { - if (testType(arguments[0][context.substitution])) { - replySuccess() - } else { - replyFail() - } - } - ) +abstract class TypeTester(typeName: String) : UnaryPredicate.Predicative(typeName) { + override fun Solve.Request.compute(first: Term): Boolean { + return testType(arguments[0][context.substitution]) } abstract fun testType(term: Term): Boolean - - companion object { - fun of(typeName: String, tester: (Term) -> Boolean): TypeTester = - object : TypeTester(typeName) { - override fun testType(term: Term): Boolean = tester(term) - } - } } \ No newline at end of file diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/UnaryPredicate.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/UnaryPredicate.kt index 61a7622b7..37cb25ea2 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/UnaryPredicate.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/UnaryPredicate.kt @@ -1,6 +1,61 @@ 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 one argument */ -abstract class UnaryPredicate(operator: String) : PrimitiveWrapper(operator, 1) +abstract class UnaryPredicate(operator: String) : PrimitiveWrapper(operator, 1) { + + /** Template method aimed at computing the application of this predicate to a [Term] */ + protected abstract fun Solve.Request.computeAll( + first: Term + ): Sequence + + final override fun uncheckedImplementation(request: Solve.Request): Sequence { + return request.computeAll(request.arguments[0]) + } + + + abstract class WithoutSideEffects(operator: String) : UnaryPredicate(operator) { + protected abstract fun Solve.Request.computeAllSubstitutions( + first: Term + ): Sequence + + final override fun Solve.Request.computeAll(first: Term): Sequence { + return computeAllSubstitutions(first).map { replyWith(it) } + } + } + + abstract class NonBacktrackable(operator: String) : UnaryPredicate(operator) { + protected abstract fun Solve.Request.computeOne( + first: Term + ): Solve.Response + + final override fun Solve.Request.computeAll(first: Term): Sequence { + return sequenceOf(computeOne(first)) + } + + } + + abstract class Functional(operator: String) : NonBacktrackable(operator) { + protected abstract fun Solve.Request.computeOneSubstitution( + first: Term + ): Substitution + + final override fun Solve.Request.computeOne(first: Term): Solve.Response { + return replyWith(computeOneSubstitution(first)) + } + } + + abstract class Predicative(operator: String) : NonBacktrackable(operator) { + protected abstract fun Solve.Request.compute( + first: Term + ): Boolean + + final override fun Solve.Request.computeOne(first: Term): Solve.Response { + return if (compute(first)) replySuccess() else replyFail() + } + } +} From add79a791620c8a03c725493e3b2570e6b972605 Mon Sep 17 00:00:00 2001 From: Giovanni Ciatto Date: Thu, 11 Jun 2020 15:40:09 +0200 Subject: [PATCH 16/20] fix built-in primitives with new wrappers hierarchy --- .../tuprolog/solve/stdlib/primitive/Throw.kt | 17 +++++----- .../solve/stdlib/primitive/AbstractAssert.kt | 33 ++++++++++--------- .../solve/stdlib/primitive/FindAll.kt | 14 ++++---- .../tuprolog/solve/stdlib/primitive/Halt.kt | 10 +++--- .../tuprolog/solve/stdlib/primitive/Is.kt | 14 +++----- .../solve/stdlib/primitive/Natural.kt | 22 ++++--------- .../solve/stdlib/primitive/NewLine.kt | 12 +++---- .../stdlib/primitive/NotUnifiableWith.kt | 9 ++--- .../solve/stdlib/primitive/Retract.kt | 20 +++++------ .../tuprolog/solve/stdlib/primitive/Sleep.kt | 13 ++++---- .../solve/stdlib/primitive/TermIdentical.kt | 10 +++--- .../stdlib/primitive/TermNotIdentical.kt | 10 +++--- .../solve/stdlib/primitive/UnifiesWith.kt | 12 +++---- .../tuprolog/solve/stdlib/primitive/Write.kt | 18 +++++----- 14 files changed, 106 insertions(+), 108 deletions(-) diff --git a/solve-classic/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/Throw.kt b/solve-classic/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/Throw.kt index d5073220f..0f1c25d9f 100644 --- a/solve-classic/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/Throw.kt +++ b/solve-classic/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/Throw.kt @@ -10,14 +10,6 @@ import it.unibo.tuprolog.solve.exception.error.MessageError import it.unibo.tuprolog.solve.primitive.UnaryPredicate object Throw : UnaryPredicate("throw") { - override fun uncheckedImplementation(request: Solve.Request): Sequence = - sequenceOf( - request.ensuringAllArgumentsAreInstantiated() - .replyException( - handleError(request.context, request.arguments[0]) - ) - ) - private fun handleError(context: ExecutionContext, error: Term): TuPrologRuntimeException = when { error is Struct && error.functor == "error" && error.arity in 1..2 -> { @@ -29,4 +21,13 @@ object Throw : UnaryPredicate("throw") { } else -> MessageError.of(error, context) } + + override fun Solve.Request.computeAll(first: Term): Sequence { + return sequenceOf( + ensuringAllArgumentsAreInstantiated() + .replyException( + handleError(context, arguments[0]) + ) + ) + } } \ No newline at end of file diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/AbstractAssert.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/AbstractAssert.kt index 0d419f530..e702758e7 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/AbstractAssert.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/AbstractAssert.kt @@ -6,21 +6,24 @@ import it.unibo.tuprolog.core.Struct import it.unibo.tuprolog.core.Term import it.unibo.tuprolog.solve.ExecutionContext import it.unibo.tuprolog.solve.Solve -import it.unibo.tuprolog.solve.primitive.SideEffect1 +import it.unibo.tuprolog.solve.primitive.UnaryPredicate -abstract class AbstractAssert(suffix: String, private val before: Boolean) : SideEffect1("assert$suffix") { - override fun accept(request: Solve.Request, term: Term): Solve.Response = - with(request.ensuringArgumentIsStruct(0)) { - val clause = if (term is Clause) term else Fact.of(term as Struct) - replySuccess( - dynamicKb = context.dynamicKb.let { - if (before) { - it.assertA(clause) - } else { - it.assertZ(clause) - } - } - ) - } +abstract class AbstractAssert( + suffix: String, + private val before: Boolean +) : UnaryPredicate.NonBacktrackable("assert$suffix") { + override fun Solve.Request.computeOne(first: Term): Solve.Response { + ensuringArgumentIsStruct(0) + val clause = if (first is Clause) first else Fact.of(first as Struct) + return replySuccess( + dynamicKb = context.dynamicKb.let { + if (before) { + it.assertA(clause) + } else { + it.assertZ(clause) + } + } + ) + } } \ No newline at end of file diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/FindAll.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/FindAll.kt index a7b42336e..bde8a8530 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/FindAll.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/FindAll.kt @@ -1,6 +1,5 @@ package it.unibo.tuprolog.solve.stdlib.primitive -import it.unibo.tuprolog.core.List as LogicList import it.unibo.tuprolog.core.Struct import it.unibo.tuprolog.core.Substitution import it.unibo.tuprolog.core.Term @@ -8,21 +7,22 @@ import it.unibo.tuprolog.solve.ExecutionContext import it.unibo.tuprolog.solve.Solution import it.unibo.tuprolog.solve.Solve import it.unibo.tuprolog.solve.exception.error.MetaError -import it.unibo.tuprolog.solve.primitive.NonBacktrackableTernaryRelation +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 : NonBacktrackableTernaryRelation("findall") { - override fun Solve.Request.computeOne(x: Term, y: Term, z: Term): Solve.Response { +object FindAll : TernaryRelation.NonBacktrackable("findall") { + override fun Solve.Request.computeOne(first: Term, second: Term, third: Term): Solve.Response { ensuringArgumentIsInstantiated(1) - val solutions = solve(y as Struct).toList() + val solutions = solve(second as Struct).toList() val error = solutions.asSequence().filterIsInstance().firstOrNull() if (error != null) { return replyException(MetaError.of(context, error.exception)) } val mapped = solutions.asSequence() .filterIsInstance() - .map { x[it.substitution].freshCopy() } + .map { first[it.substitution].freshCopy() } - return replySuccess(z.mguWith(LogicList.from(mapped)) as Substitution.Unifier) + return replySuccess(third.mguWith(LogicList.from(mapped)) as Substitution.Unifier) } } \ No newline at end of file diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/Halt.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/Halt.kt index b5ce35d6e..c8e4d6ec7 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/Halt.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/Halt.kt @@ -3,15 +3,15 @@ package it.unibo.tuprolog.solve.stdlib.primitive import it.unibo.tuprolog.solve.ExecutionContext import it.unibo.tuprolog.solve.Solve import it.unibo.tuprolog.solve.exception.HaltException -import it.unibo.tuprolog.solve.primitive.PrimitiveWrapper +import it.unibo.tuprolog.solve.primitive.PredicateWithoutArguments /** * Implementation of primitive handling `halt/0` behaviour * * @author Enrico */ -object Halt : PrimitiveWrapper("halt", 0) { - - override fun uncheckedImplementation(request: Solve.Request): Sequence = - throw HaltException(context = request.context) +object Halt : PredicateWithoutArguments.NonBacktrackable("halt") { + override fun Solve.Request.computeOne(): Solve.Response { + throw HaltException(context = context) + } } diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/Is.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/Is.kt index 57b7ebd2f..5be42da4c 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/Is.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/Is.kt @@ -5,7 +5,7 @@ import it.unibo.tuprolog.core.Term import it.unibo.tuprolog.solve.ExecutionContext import it.unibo.tuprolog.solve.Solve import it.unibo.tuprolog.solve.function.ArithmeticEvaluator -import it.unibo.tuprolog.solve.primitive.TermRelation +import it.unibo.tuprolog.solve.primitive.BinaryRelation import it.unibo.tuprolog.unify.Unificator.Companion.mguWith /** @@ -13,16 +13,12 @@ import it.unibo.tuprolog.unify.Unificator.Companion.mguWith * * @author Enrico */ -object Is : TermRelation.WithSideEffects("is") { +object Is : BinaryRelation.Functional("is") { + private fun mgu(x: Term, y: Term): Substitution = x mguWith y - override fun Solve.Request.computeSingleResponse(): Solve.Response = + override fun Solve.Request.computeOneSubstitution(first: Term, second: Term): Substitution = ArithmeticEvaluator(context).let { - when (val effects: Substitution = relationWithSideEffects(arguments[0], arguments[1].accept(it))) { - is Substitution.Unifier -> replySuccess(effects) - else -> replyFail() - } + mgu(arguments[0], arguments[1].accept(it)) } - override fun relationWithSideEffects(x: Term, y: Term): Substitution = - x mguWith y } diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/Natural.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/Natural.kt index 7582498c8..47ef2086a 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/Natural.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/Natural.kt @@ -11,23 +11,15 @@ import org.gciatto.kt.math.BigInteger // TODO doc object Natural : UnaryPredicate("natural") { - override fun uncheckedImplementation(request: Solve.Request): Sequence = - when (val x = request.arguments[0]) { - is Var -> generateValues(x).map { request.replySuccess(Substitution.of(x, it)) } - is Integer -> sequenceOf(request.replyWith(checkValue(x))) - else -> sequenceOf(request.replyFail()) + override fun Solve.Request.computeAll(first: Term): Sequence = + when (first) { + is Var -> generateValues().map { replySuccess(Substitution.of(first, it)) } + is Integer -> sequenceOf(replyWith(checkValue(first))) + else -> sequenceOf(replyFail()) } - @Suppress("UNUSED_PARAMETER") - private fun generateValues(variable: Var): Sequence = sequence { - var i = BigInteger.ZERO - - while (true) { - yield(Integer.of(i)) - - i += BigInteger.ONE - } - } + private fun generateValues(): Sequence = + generateSequence(BigInteger.ZERO) { it + BigInteger.ONE }.map { Integer.of(it) } private fun checkValue(value: Integer): Boolean = value.intValue.signum >= 0 diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/NewLine.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/NewLine.kt index d4b433725..fbca19260 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/NewLine.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/NewLine.kt @@ -2,16 +2,16 @@ package it.unibo.tuprolog.solve.stdlib.primitive import it.unibo.tuprolog.solve.ExecutionContext import it.unibo.tuprolog.solve.Solve -import it.unibo.tuprolog.solve.primitive.SideEffect0 +import it.unibo.tuprolog.solve.primitive.PredicateWithoutArguments -object NewLine : SideEffect0("nl") { - override fun accept(request: Solve.Request): Solve.Response { - return request.context.standardOutput.let { +object NewLine : PredicateWithoutArguments.NonBacktrackable("nl") { + override fun Solve.Request.computeOne(): Solve.Response { + return context.standardOutput.let { if (it == null) { - request.replyFail() + replyFail() } else { it.write("\n") - request.replySuccess() + replySuccess() } } } diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/NotUnifiableWith.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/NotUnifiableWith.kt index e2152da09..b4b917c26 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/NotUnifiableWith.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/NotUnifiableWith.kt @@ -2,11 +2,12 @@ package it.unibo.tuprolog.solve.stdlib.primitive import it.unibo.tuprolog.core.Term import it.unibo.tuprolog.solve.ExecutionContext -import it.unibo.tuprolog.solve.primitive.TermRelation +import it.unibo.tuprolog.solve.Solve +import it.unibo.tuprolog.solve.primitive.BinaryRelation import it.unibo.tuprolog.unify.Unificator.Companion.matches /** Implementation of '\='/2 predicate */ -object NotUnifiableWith : TermRelation.WithoutSideEffects("\\=") { - override fun relationWithoutSideEffects(x: Term, y: Term): Boolean = - (x matches y).not() +object NotUnifiableWith : BinaryRelation.Predicative("\\=") { + override fun Solve.Request.compute(first: Term, second: Term): Boolean = + (first matches second).not() } diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/Retract.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/Retract.kt index 6584101df..0791692da 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/Retract.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/Retract.kt @@ -4,26 +4,26 @@ import it.unibo.tuprolog.core.* import it.unibo.tuprolog.core.Var import it.unibo.tuprolog.solve.ExecutionContext import it.unibo.tuprolog.solve.Solve -import it.unibo.tuprolog.solve.primitive.BacktrackableSideEffect1 +import it.unibo.tuprolog.solve.primitive.UnaryPredicate import it.unibo.tuprolog.theory.RetractResult import it.unibo.tuprolog.unify.Unificator.Companion.mguWith -object Retract: BacktrackableSideEffect1("retract") { - override fun accept(request: Solve.Request, term: Term): Sequence { - request.ensuringArgumentIsStruct(0) - val clause = if (term is Clause) term else Rule.of(term as Struct, Var.anonymous()) +object Retract : UnaryPredicate("retract") { + override fun Solve.Request.computeAll(first: Term): Sequence { + ensuringArgumentIsStruct(0) + val clause = if (first is Clause) first else Rule.of(first as Struct, Var.anonymous()) return sequence { - var dynamicKb = request.context.dynamicKb + var dynamicKb = context.dynamicKb while (true) { val result = dynamicKb.retract(clause) if (result is RetractResult.Success) { dynamicKb = result.theory - val substitution = when (term) { - is Clause -> (term mguWith result.firstClause) as Substitution.Unifier - else -> (term mguWith result.firstClause.head!!) as Substitution.Unifier + val substitution = when (first) { + is Clause -> (first mguWith result.firstClause) as Substitution.Unifier + else -> (first mguWith result.firstClause.head!!) as Substitution.Unifier } yield( - request.replySuccess(substitution = substitution, dynamicKb = dynamicKb) + replySuccess(substitution = substitution, dynamicKb = dynamicKb) ) } else { break diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/Sleep.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/Sleep.kt index 540a0bcd0..7a353b60f 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/Sleep.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/Sleep.kt @@ -1,26 +1,27 @@ package it.unibo.tuprolog.solve.stdlib.primitive import it.unibo.tuprolog.core.Integer +import it.unibo.tuprolog.core.Term import it.unibo.tuprolog.solve.ExecutionContext import it.unibo.tuprolog.solve.Solve import it.unibo.tuprolog.solve.currentTimeInstant import it.unibo.tuprolog.solve.exception.TimeOutException -import it.unibo.tuprolog.solve.primitive.PrimitiveWrapper +import it.unibo.tuprolog.solve.primitive.UnaryPredicate /** * Implements predicate `sleep(+N)` where `N` must be instantiated as an integer. * The predicate execution always succeeds, unless the resolution process is halted because of a [TimeOutException]. * Furthermore, the resolution of a `sleep(N)` sub-goal is guaranteed to require at least `N` milliseconds */ -object Sleep : PrimitiveWrapper("sleep", 1) { - override fun uncheckedImplementation(request: Solve.Request): Sequence = +object Sleep : UnaryPredicate("sleep") { + override fun Solve.Request.computeAll(first: Term): Sequence = sequence { - request.ensuringAllArgumentsAreInstantiated() + ensuringAllArgumentsAreInstantiated() .ensuringArgumentIsInteger(0).let { val initialTime = currentTimeInstant() - val threshold = request.arguments[0].castTo().intValue.toLongExact() + val threshold = arguments[0].castTo().intValue.toLongExact() while (currentTimeInstant() - initialTime < threshold); - yield(request.replySuccess()) + yield(replySuccess()) } } } \ No newline at end of file diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/TermIdentical.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/TermIdentical.kt index e9e4b8f4e..9ce2182da 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/TermIdentical.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/TermIdentical.kt @@ -2,10 +2,12 @@ package it.unibo.tuprolog.solve.stdlib.primitive import it.unibo.tuprolog.core.Term import it.unibo.tuprolog.solve.ExecutionContext -import it.unibo.tuprolog.solve.primitive.TermRelation +import it.unibo.tuprolog.solve.Solve +import it.unibo.tuprolog.solve.primitive.BinaryRelation /** Implementation of '=='/2 predicate */ -object TermIdentical : TermRelation.WithoutSideEffects("==") { - override fun relationWithoutSideEffects(x: Term, y: Term): Boolean = - x == y +object TermIdentical : BinaryRelation.Predicative("==") { + override fun Solve.Request.compute(first: Term, second: Term): Boolean { + return first == second + } } diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/TermNotIdentical.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/TermNotIdentical.kt index 9c863aadd..70e71a51e 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/TermNotIdentical.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/TermNotIdentical.kt @@ -2,10 +2,12 @@ package it.unibo.tuprolog.solve.stdlib.primitive import it.unibo.tuprolog.core.Term import it.unibo.tuprolog.solve.ExecutionContext -import it.unibo.tuprolog.solve.primitive.TermRelation +import it.unibo.tuprolog.solve.Solve +import it.unibo.tuprolog.solve.primitive.BinaryRelation /** Implementation of `'\=='/2` predicate */ -object TermNotIdentical : TermRelation.WithoutSideEffects("\\==") { - override fun relationWithoutSideEffects(x: Term, y: Term): Boolean = - x != y +object TermNotIdentical : BinaryRelation.Predicative("\\==") { + override fun Solve.Request.compute(first: Term, second: Term): Boolean { + return first != second + } } diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/UnifiesWith.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/UnifiesWith.kt index 55345d67b..554ba3204 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/UnifiesWith.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/UnifiesWith.kt @@ -1,13 +1,13 @@ package it.unibo.tuprolog.solve.stdlib.primitive -import it.unibo.tuprolog.core.Substitution import it.unibo.tuprolog.core.Term import it.unibo.tuprolog.solve.ExecutionContext -import it.unibo.tuprolog.solve.primitive.TermRelation -import it.unibo.tuprolog.unify.Unificator.Companion.mguWith +import it.unibo.tuprolog.solve.Solve +import it.unibo.tuprolog.solve.primitive.BinaryRelation +import it.unibo.tuprolog.unify.Unificator.Companion.matches /** Implementation of '='/2 predicate */ -object UnifiesWith : TermRelation.WithSideEffects("=") { - override fun relationWithSideEffects(x: Term, y: Term): Substitution = - x mguWith y +object UnifiesWith : BinaryRelation.Predicative("=") { + override fun Solve.Request.compute(first: Term, second: Term): Boolean = + first matches second } diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/Write.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/Write.kt index 7c181cff3..96e7f6503 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/Write.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/Write.kt @@ -4,20 +4,20 @@ import it.unibo.tuprolog.core.Atom import it.unibo.tuprolog.core.Term import it.unibo.tuprolog.solve.ExecutionContext import it.unibo.tuprolog.solve.Solve -import it.unibo.tuprolog.solve.primitive.SideEffect1 +import it.unibo.tuprolog.solve.primitive.UnaryPredicate -object Write : SideEffect1("write") { - override fun accept(request: Solve.Request, term: Term): Solve.Response { - return request.context.standardOutput.let { +object Write : UnaryPredicate.NonBacktrackable("write") { + override fun Solve.Request.computeOne(first: Term): Solve.Response { + return context.standardOutput.let { if (it == null) { - request.replyFail() + replyFail() } else { - val string = when (term) { - is Atom -> term.value - else -> term.toString() + val string = when (first) { + is Atom -> first.value + else -> first.toString() } it.write(string) - request.replySuccess() + replySuccess() } } } From 78fe73105c831b13726e548baad3344c44b51fa5 Mon Sep 17 00:00:00 2001 From: Giovanni Ciatto Date: Thu, 11 Jun 2020 16:10:08 +0200 Subject: [PATCH 17/20] minor bug fixes to ArithmeticRelation.kt --- .../solve/primitive/ArithmeticRelation.kt | 15 ++++++++++----- .../solve/stdlib/primitive/ArithmeticEqual.kt | 2 +- .../stdlib/primitive/ArithmeticGreaterThan.kt | 2 +- .../primitive/ArithmeticGreaterThanOrEqualTo.kt | 2 +- .../solve/stdlib/primitive/ArithmeticLowerThan.kt | 2 +- .../primitive/ArithmeticLowerThanOrEqualTo.kt | 2 +- .../solve/stdlib/primitive/ArithmeticNotEqual.kt | 2 +- .../unibo/tuprolog/solve/stdlib/primitive/Is.kt | 4 +--- .../solve/stdlib/primitive/UnifiesWith.kt | 9 +++++---- .../stdlib/primitive/testutils/ArithmeticUtils.kt | 7 ++++--- 10 files changed, 26 insertions(+), 21 deletions(-) diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/ArithmeticRelation.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/ArithmeticRelation.kt index a030e4919..0e95a114a 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/ArithmeticRelation.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/ArithmeticRelation.kt @@ -4,15 +4,20 @@ import it.unibo.tuprolog.core.Numeric import it.unibo.tuprolog.core.Term import it.unibo.tuprolog.solve.ExecutionContext import it.unibo.tuprolog.solve.Solve +import it.unibo.tuprolog.solve.function.ArithmeticEvaluator /** Base class for implementing arithmetic relation between [Numeric] terms */ abstract class ArithmeticRelation(operator: String) : BinaryRelation.Predicative(operator) { - override fun Solve.Request.compute(first: Term, second: Term): Boolean { - ensuringArgumentIsNumeric(1) - ensuringArgumentIsNumeric(2) - return arithmeticRelation(first as Numeric, second as Numeric) + final override fun Solve.Request.compute(first: Term, second: Term): Boolean { + ensuringAllArgumentsAreInstantiated().ensuringArgumentIsNumeric(0).ensuringArgumentIsNumeric(1) + return evaluateAndCompute(first, second as Numeric) } - abstract fun arithmeticRelation(x: Numeric, y: Numeric): Boolean + private fun Solve.Request.evaluateAndCompute(x: Term, y: Term): Boolean = + ArithmeticEvaluator(context).let { + computeNumeric(x.accept(it) as Numeric, y.accept(it) as Numeric) + } + + abstract fun computeNumeric(x: Numeric, y: Numeric): Boolean } diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/ArithmeticEqual.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/ArithmeticEqual.kt index b4f68dca4..b96756334 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/ArithmeticEqual.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/ArithmeticEqual.kt @@ -6,6 +6,6 @@ import it.unibo.tuprolog.solve.primitive.ArithmeticRelation /** Implementation of '=:='/2 predicate */ object ArithmeticEqual : ArithmeticRelation("=:=") { - override fun arithmeticRelation(x: Numeric, y: Numeric): Boolean = + override fun computeNumeric(x: Numeric, y: Numeric): Boolean = x.compareValueTo(y) == 0 } diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/ArithmeticGreaterThan.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/ArithmeticGreaterThan.kt index 23c708f0e..dfb02d3d4 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/ArithmeticGreaterThan.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/ArithmeticGreaterThan.kt @@ -6,6 +6,6 @@ import it.unibo.tuprolog.solve.primitive.ArithmeticRelation /** Implementation of '>'/2 predicate */ object ArithmeticGreaterThan : ArithmeticRelation(">") { - override fun arithmeticRelation(x: Numeric, y: Numeric): Boolean = + override fun computeNumeric(x: Numeric, y: Numeric): Boolean = x.compareValueTo(y) > 0 } diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/ArithmeticGreaterThanOrEqualTo.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/ArithmeticGreaterThanOrEqualTo.kt index 7971a8340..912b7e5d6 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/ArithmeticGreaterThanOrEqualTo.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/ArithmeticGreaterThanOrEqualTo.kt @@ -6,6 +6,6 @@ import it.unibo.tuprolog.solve.primitive.ArithmeticRelation /** Implementation of '>='/2 predicate */ object ArithmeticGreaterThanOrEqualTo : ArithmeticRelation(">=") { - override fun arithmeticRelation(x: Numeric, y: Numeric): Boolean = + override fun computeNumeric(x: Numeric, y: Numeric): Boolean = x.compareValueTo(y) >= 0 } diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/ArithmeticLowerThan.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/ArithmeticLowerThan.kt index 4b9b2ef6e..f6b2ff0cb 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/ArithmeticLowerThan.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/ArithmeticLowerThan.kt @@ -6,6 +6,6 @@ import it.unibo.tuprolog.solve.primitive.ArithmeticRelation /** Implementation of '<'/2 predicate */ object ArithmeticLowerThan : ArithmeticRelation("<") { - override fun arithmeticRelation(x: Numeric, y: Numeric): Boolean = + override fun computeNumeric(x: Numeric, y: Numeric): Boolean = x.compareValueTo(y) < 0 } diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/ArithmeticLowerThanOrEqualTo.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/ArithmeticLowerThanOrEqualTo.kt index 3ebb7dc2a..3e34c7e19 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/ArithmeticLowerThanOrEqualTo.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/ArithmeticLowerThanOrEqualTo.kt @@ -6,6 +6,6 @@ import it.unibo.tuprolog.solve.primitive.ArithmeticRelation /** Implementation of '=<'/2 predicate */ object ArithmeticLowerThanOrEqualTo : ArithmeticRelation("=<") { - override fun arithmeticRelation(x: Numeric, y: Numeric): Boolean = + override fun computeNumeric(x: Numeric, y: Numeric): Boolean = x.compareValueTo(y) <= 0 } diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/ArithmeticNotEqual.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/ArithmeticNotEqual.kt index 0ead36832..7c1696567 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/ArithmeticNotEqual.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/ArithmeticNotEqual.kt @@ -6,6 +6,6 @@ import it.unibo.tuprolog.solve.primitive.ArithmeticRelation /** Implementation of '=\='/2 predicate */ object ArithmeticNotEqual : ArithmeticRelation("=\\=") { - override fun arithmeticRelation(x: Numeric, y: Numeric): Boolean = + override fun computeNumeric(x: Numeric, y: Numeric): Boolean = x.compareValueTo(y) != 0 } diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/Is.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/Is.kt index 5be42da4c..b9c91303b 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/Is.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/Is.kt @@ -17,8 +17,6 @@ object Is : BinaryRelation.Functional("is") { private fun mgu(x: Term, y: Term): Substitution = x mguWith y override fun Solve.Request.computeOneSubstitution(first: Term, second: Term): Substitution = - ArithmeticEvaluator(context).let { - mgu(arguments[0], arguments[1].accept(it)) - } + mgu(arguments[0], arguments[1].accept(ArithmeticEvaluator(context))) } diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/UnifiesWith.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/UnifiesWith.kt index 554ba3204..11b2428ca 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/UnifiesWith.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/UnifiesWith.kt @@ -1,13 +1,14 @@ package it.unibo.tuprolog.solve.stdlib.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 import it.unibo.tuprolog.solve.primitive.BinaryRelation -import it.unibo.tuprolog.unify.Unificator.Companion.matches +import it.unibo.tuprolog.unify.Unificator.Companion.mguWith /** Implementation of '='/2 predicate */ -object UnifiesWith : BinaryRelation.Predicative("=") { - override fun Solve.Request.compute(first: Term, second: Term): Boolean = - first matches second +object UnifiesWith : BinaryRelation.Functional("=") { + override fun Solve.Request.computeOneSubstitution(first: Term, second: Term): Substitution = + first mguWith second } diff --git a/test-solve/src/commonTest/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/testutils/ArithmeticUtils.kt b/test-solve/src/commonTest/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/testutils/ArithmeticUtils.kt index 938bb4a88..c5b2fa75d 100644 --- a/test-solve/src/commonTest/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/testutils/ArithmeticUtils.kt +++ b/test-solve/src/commonTest/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/testutils/ArithmeticUtils.kt @@ -2,15 +2,16 @@ package it.unibo.tuprolog.solve.stdlib.primitive.testutils import it.unibo.tuprolog.core.Substitution import it.unibo.tuprolog.dsl.prolog -import it.unibo.tuprolog.solve.stdlib.primitive.* -import it.unibo.tuprolog.solve.stdlib.primitive.testutils.PrimitiveUtils.createSolveRequest import it.unibo.tuprolog.solve.ExecutionContext import it.unibo.tuprolog.solve.Solution import it.unibo.tuprolog.solve.Solve import it.unibo.tuprolog.solve.exception.TuPrologRuntimeException import it.unibo.tuprolog.solve.exception.error.EvaluationError import it.unibo.tuprolog.solve.exception.error.InstantiationError +import it.unibo.tuprolog.solve.exception.error.TypeError import it.unibo.tuprolog.solve.primitive.ArithmeticRelation +import it.unibo.tuprolog.solve.stdlib.primitive.* +import it.unibo.tuprolog.solve.stdlib.primitive.testutils.PrimitiveUtils.createSolveRequest import kotlin.reflect.KClass import kotlin.test.assertFailsWith import kotlin.test.assertTrue @@ -65,7 +66,7 @@ internal object ArithmeticUtils { ArithmeticEqual.functor("*"(3, 2), "-"(7, 1)) to true, ArithmeticEqual.functor(0.333, "/"(1, 3)) to false, ArithmeticEqual.functor(0, 1) to false, - ArithmeticEqual.functor(1, "+"("N", "/"(3, 0))) to InstantiationError::class + ArithmeticEqual.functor(1, "+"("N", "/"(3, 0))) to TypeError::class ).mapKeys { (query, _) -> createSolveRequest(query) } } } From 003cc1c60793257c45c85c7d4fed831b124cac8e Mon Sep 17 00:00:00 2001 From: Giovanni Ciatto Date: Thu, 11 Jun 2020 16:10:25 +0200 Subject: [PATCH 18/20] improve prolog errors construction --- .../exception/error/InstantiationError.kt | 2 +- .../solve/exception/error/TypeError.kt | 16 +++++++------- .../solve/primitive/PrimitiveWrapper.kt | 22 +++---------------- 3 files changed, 12 insertions(+), 28 deletions(-) diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/exception/error/InstantiationError.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/exception/error/InstantiationError.kt index 73b240c1d..99944c002 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/exception/error/InstantiationError.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/exception/error/InstantiationError.kt @@ -45,7 +45,7 @@ class InstantiationError( fun forArgument(context: ExecutionContext, procedure: Signature, index: Int? = null, variable: Var? = null) = InstantiationError( - message = "Argument ${index ?: ""} `${variable ?: ""}` of $procedure is unexpectedly not instantiated", + message = "Argument ${index ?: ""} `${variable ?: ""}` of ${procedure.toIndicator()} is unexpectedly not instantiated", context = context, extraData = variable ) diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/exception/error/TypeError.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/exception/error/TypeError.kt index 2512950a5..39748a24d 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/exception/error/TypeError.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/exception/error/TypeError.kt @@ -44,7 +44,7 @@ class TypeError( index: Int? = null ) : this( message = "Argument ${index - ?: ""} of `$procedure` should be a `$expectedType`, but `$actualValue` has been provided instead", + ?: ""} of `${procedure.toIndicator()}` should be a `$expectedType`, but `$actualValue` has been provided instead", context = context, expectedType = expectedType, actualValue = actualValue, @@ -64,13 +64,13 @@ class TypeError( actualValue: Term, index: Int? = null ) = TypeError( - message = "Argument ${index - ?: ""} of `$procedure` should be a `$expectedType`, but `$actualValue` has been provided instead", - context = context, - expectedType = expectedType, - actualValue = actualValue, - extraData = actualValue - ) + message = "Argument ${index + ?: ""} of `${procedure.toIndicator()}` should be a `$expectedType`, but `$actualValue` has been provided instead", + context = context, + expectedType = expectedType, + actualValue = actualValue, + extraData = actualValue + ) fun forGoal( context: ExecutionContext, diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/PrimitiveWrapper.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/PrimitiveWrapper.kt index 341e2fd09..0b4cd935d 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/PrimitiveWrapper.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/PrimitiveWrapper.kt @@ -7,7 +7,6 @@ import it.unibo.tuprolog.solve.Signature import it.unibo.tuprolog.solve.Solve import it.unibo.tuprolog.solve.exception.error.InstantiationError import it.unibo.tuprolog.solve.exception.error.TypeError -import it.unibo.tuprolog.solve.primitive.PrimitiveWrapper.Companion.ensuringArgumentIsInstantiated /** * Wrapper class for [Primitive] implementation @@ -89,34 +88,19 @@ abstract class PrimitiveWrapper : AbstractWrapper Solve.Request.ensuringArgumentIsNumeric(index: Int): Solve.Request = when (val arg = arguments[index]) { - !is Numeric -> throw TypeError( - "Argument $index of ${this.signature}` should be a ${TypeError.Expected.NUMBER}", - context = context, - expectedType = TypeError.Expected.NUMBER, - actualValue = arg - ) + !is Numeric -> throw TypeError.forArgument(context, signature, TypeError.Expected.NUMBER, arg, index) else -> this } fun Solve.Request.ensuringArgumentIsStruct(index: Int): Solve.Request = when (val arg = arguments[index]) { - !is Struct -> throw TypeError( - "Argument $index of ${this.signature}` should be a ${TypeError.Expected.COMPOUND}", - context = context, - expectedType = TypeError.Expected.COMPOUND, - actualValue = arg - ) + !is Struct -> throw TypeError.forArgument(context, signature, TypeError.Expected.COMPOUND, arg, index) else -> this } fun Solve.Request.ensuringArgumentIsInteger(index: Int): Solve.Request = when (val arg = arguments[index]) { - !is Integer -> throw TypeError( - "Argument $index of ${this.signature}` should be a ${TypeError.Expected.INTEGER}", - context = context, - expectedType = TypeError.Expected.INTEGER, - actualValue = arg - ) + !is Integer -> throw TypeError.forArgument(context, signature, TypeError.Expected.INTEGER, arg, index) else -> this } } From afc09b21ebb8fc1601838bd64de8adeba98c1cc5 Mon Sep 17 00:00:00 2001 From: Giovanni Ciatto Date: Fri, 12 Jun 2020 09:24:31 +0200 Subject: [PATCH 19/20] fix ArithmeticRelation to pass broken tests in :test-solve --- .../it/unibo/tuprolog/solve/primitive/ArithmeticRelation.kt | 4 ++-- .../solve/stdlib/primitive/testutils/ArithmeticUtils.kt | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/ArithmeticRelation.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/ArithmeticRelation.kt index 0e95a114a..a252eddbb 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/ArithmeticRelation.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/primitive/ArithmeticRelation.kt @@ -10,8 +10,8 @@ import it.unibo.tuprolog.solve.function.ArithmeticEvaluator abstract class ArithmeticRelation(operator: String) : BinaryRelation.Predicative(operator) { final override fun Solve.Request.compute(first: Term, second: Term): Boolean { - ensuringAllArgumentsAreInstantiated().ensuringArgumentIsNumeric(0).ensuringArgumentIsNumeric(1) - return evaluateAndCompute(first, second as Numeric) + ensuringAllArgumentsAreInstantiated() + return evaluateAndCompute(first, second) } private fun Solve.Request.evaluateAndCompute(x: Term, y: Term): Boolean = diff --git a/test-solve/src/commonTest/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/testutils/ArithmeticUtils.kt b/test-solve/src/commonTest/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/testutils/ArithmeticUtils.kt index c5b2fa75d..b09806ea7 100644 --- a/test-solve/src/commonTest/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/testutils/ArithmeticUtils.kt +++ b/test-solve/src/commonTest/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/testutils/ArithmeticUtils.kt @@ -66,7 +66,7 @@ internal object ArithmeticUtils { ArithmeticEqual.functor("*"(3, 2), "-"(7, 1)) to true, ArithmeticEqual.functor(0.333, "/"(1, 3)) to false, ArithmeticEqual.functor(0, 1) to false, - ArithmeticEqual.functor(1, "+"("N", "/"(3, 0))) to TypeError::class + ArithmeticEqual.functor(1, "+"("N", "/"(3, 0))) to InstantiationError::class ).mapKeys { (query, _) -> createSolveRequest(query) } } } From cdc872a5dbbd78085e35cff33bc6c3375680ae24 Mon Sep 17 00:00:00 2001 From: Giovanni Ciatto Date: Fri, 12 Jun 2020 09:43:20 +0200 Subject: [PATCH 20/20] move abstract function base classes in package it.unibo.tuprolog.solve.function --- .../function/BinaryMathFunction.kt | 3 +-- .../function/IntegersBinaryMathFunction.kt | 20 +++++++++++++++---- .../{stdlib => }/function/MathFunction.kt | 3 +-- .../function/NullaryMathFunction.kt | 3 +-- .../function/UnaryMathFunction.kt | 3 +-- .../solve/stdlib/function/AbsoluteValue.kt | 1 + .../solve/stdlib/function/Addition.kt | 1 + .../solve/stdlib/function/ArcTangent.kt | 1 + .../solve/stdlib/function/BitwiseAnd.kt | 1 + .../stdlib/function/BitwiseComplement.kt | 1 + .../solve/stdlib/function/BitwiseLeftShift.kt | 1 + .../solve/stdlib/function/BitwiseOr.kt | 1 + .../stdlib/function/BitwiseRightShift.kt | 1 + .../tuprolog/solve/stdlib/function/Ceiling.kt | 1 + .../tuprolog/solve/stdlib/function/Cosine.kt | 1 + .../solve/stdlib/function/Exponential.kt | 1 + .../solve/stdlib/function/Exponentiation.kt | 1 + .../stdlib/function/FloatFractionalPart.kt | 1 + .../solve/stdlib/function/FloatIntegerPart.kt | 1 + .../stdlib/function/FloatingPointDivision.kt | 1 + .../tuprolog/solve/stdlib/function/Floor.kt | 1 + .../solve/stdlib/function/IntegerDivision.kt | 1 + .../tuprolog/solve/stdlib/function/Modulo.kt | 1 + .../solve/stdlib/function/Multiplication.kt | 1 + .../solve/stdlib/function/NaturalLogarithm.kt | 1 + .../solve/stdlib/function/Remainder.kt | 1 + .../tuprolog/solve/stdlib/function/Round.kt | 1 + .../tuprolog/solve/stdlib/function/Sign.kt | 1 + .../solve/stdlib/function/SignReversal.kt | 1 + .../tuprolog/solve/stdlib/function/Sine.kt | 1 + .../solve/stdlib/function/SquareRoot.kt | 1 + .../solve/stdlib/function/Subtraction.kt | 1 + .../tuprolog/solve/stdlib/function/ToFloat.kt | 1 + .../solve/stdlib/function/Truncate.kt | 1 + .../function/testutils/FunctionUtils.kt | 10 +++++----- 35 files changed, 54 insertions(+), 17 deletions(-) rename solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/{stdlib => }/function/BinaryMathFunction.kt (95%) rename solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/{stdlib => }/function/IntegersBinaryMathFunction.kt (62%) rename solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/{stdlib => }/function/MathFunction.kt (95%) rename solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/{stdlib => }/function/NullaryMathFunction.kt (86%) rename solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/{stdlib => }/function/UnaryMathFunction.kt (91%) diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/BinaryMathFunction.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/function/BinaryMathFunction.kt similarity index 95% rename from solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/BinaryMathFunction.kt rename to solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/function/BinaryMathFunction.kt index 70504ebe3..a72bd326d 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/BinaryMathFunction.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/function/BinaryMathFunction.kt @@ -1,10 +1,9 @@ -package it.unibo.tuprolog.solve.stdlib.function +package it.unibo.tuprolog.solve.function import it.unibo.tuprolog.core.Integer import it.unibo.tuprolog.core.Numeric import it.unibo.tuprolog.core.Real import it.unibo.tuprolog.solve.ExecutionContext -import it.unibo.tuprolog.solve.function.Compute /** * Base class to implement unary math functions diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/IntegersBinaryMathFunction.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/function/IntegersBinaryMathFunction.kt similarity index 62% rename from solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/IntegersBinaryMathFunction.kt rename to solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/function/IntegersBinaryMathFunction.kt index ec899a767..12b897150 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/IntegersBinaryMathFunction.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/function/IntegersBinaryMathFunction.kt @@ -1,4 +1,4 @@ -package it.unibo.tuprolog.solve.stdlib.function +package it.unibo.tuprolog.solve.function import it.unibo.tuprolog.core.Integer import it.unibo.tuprolog.core.Numeric @@ -15,11 +15,23 @@ import it.unibo.tuprolog.solve.ExecutionContext abstract class IntegersBinaryMathFunction(name: String) : BinaryMathFunction(name) { override fun mathFunction(real: Real, integer: Integer, context: ExecutionContext): Numeric = - throwTypeErrorBecauseOnlyIntegersAccepted(functor, real, context) + throwTypeErrorBecauseOnlyIntegersAccepted( + functor, + real, + context + ) override fun mathFunction(integer: Integer, real: Real, context: ExecutionContext): Numeric = - throwTypeErrorBecauseOnlyIntegersAccepted(functor, real, context) + throwTypeErrorBecauseOnlyIntegersAccepted( + functor, + real, + context + ) override fun mathFunction(real1: Real, real2: Real, context: ExecutionContext): Numeric = - throwTypeErrorBecauseOnlyIntegersAccepted(functor, real1, context) + throwTypeErrorBecauseOnlyIntegersAccepted( + functor, + real1, + context + ) } diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/MathFunction.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/function/MathFunction.kt similarity index 95% rename from solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/MathFunction.kt rename to solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/function/MathFunction.kt index ead1b80e6..063771f22 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/MathFunction.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/function/MathFunction.kt @@ -1,11 +1,10 @@ -package it.unibo.tuprolog.solve.stdlib.function +package it.unibo.tuprolog.solve.function import it.unibo.tuprolog.core.Term import it.unibo.tuprolog.solve.ExecutionContext import it.unibo.tuprolog.solve.Signature import it.unibo.tuprolog.solve.exception.error.EvaluationError import it.unibo.tuprolog.solve.exception.error.TypeError -import it.unibo.tuprolog.solve.function.FunctionWrapper import kotlin.jvm.JvmStatic /** diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/NullaryMathFunction.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/function/NullaryMathFunction.kt similarity index 86% rename from solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/NullaryMathFunction.kt rename to solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/function/NullaryMathFunction.kt index 391df6f1a..e16a0928e 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/NullaryMathFunction.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/function/NullaryMathFunction.kt @@ -1,8 +1,7 @@ -package it.unibo.tuprolog.solve.stdlib.function +package it.unibo.tuprolog.solve.function import it.unibo.tuprolog.core.Numeric import it.unibo.tuprolog.solve.ExecutionContext -import it.unibo.tuprolog.solve.function.Compute /** * Base class to implement nullary math functions (with no arguments) diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/UnaryMathFunction.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/function/UnaryMathFunction.kt similarity index 91% rename from solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/UnaryMathFunction.kt rename to solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/function/UnaryMathFunction.kt index b5b30bad5..2c6cffeac 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/UnaryMathFunction.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/function/UnaryMathFunction.kt @@ -1,10 +1,9 @@ -package it.unibo.tuprolog.solve.stdlib.function +package it.unibo.tuprolog.solve.function import it.unibo.tuprolog.core.Integer import it.unibo.tuprolog.core.Numeric import it.unibo.tuprolog.core.Real import it.unibo.tuprolog.solve.ExecutionContext -import it.unibo.tuprolog.solve.function.Compute /** * Base class to implement unary math functions diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/AbsoluteValue.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/AbsoluteValue.kt index a1a17ad19..eb606eed4 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/AbsoluteValue.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/AbsoluteValue.kt @@ -4,6 +4,7 @@ import it.unibo.tuprolog.core.Integer import it.unibo.tuprolog.core.Numeric import it.unibo.tuprolog.core.Real import it.unibo.tuprolog.solve.ExecutionContext +import it.unibo.tuprolog.solve.function.UnaryMathFunction /** * Implementation of `abs/1` arithmetic functor diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/Addition.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/Addition.kt index 554af654a..186c1c5ef 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/Addition.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/Addition.kt @@ -4,6 +4,7 @@ import it.unibo.tuprolog.core.Integer import it.unibo.tuprolog.core.Numeric import it.unibo.tuprolog.core.Real import it.unibo.tuprolog.solve.ExecutionContext +import it.unibo.tuprolog.solve.function.BinaryMathFunction import org.gciatto.kt.math.BigDecimal /** diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/ArcTangent.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/ArcTangent.kt index dd45dac87..4ce0295ba 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/ArcTangent.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/ArcTangent.kt @@ -4,6 +4,7 @@ import it.unibo.tuprolog.core.Integer import it.unibo.tuprolog.core.Numeric import it.unibo.tuprolog.core.Real import it.unibo.tuprolog.solve.ExecutionContext +import it.unibo.tuprolog.solve.function.UnaryMathFunction import org.gciatto.kt.math.BigDecimal import kotlin.math.atan diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/BitwiseAnd.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/BitwiseAnd.kt index bce4c65e5..98c2c335f 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/BitwiseAnd.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/BitwiseAnd.kt @@ -3,6 +3,7 @@ package it.unibo.tuprolog.solve.stdlib.function import it.unibo.tuprolog.core.Integer import it.unibo.tuprolog.core.Numeric import it.unibo.tuprolog.solve.ExecutionContext +import it.unibo.tuprolog.solve.function.IntegersBinaryMathFunction /** * Implementation of `'/\'/2` arithmetic functor diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/BitwiseComplement.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/BitwiseComplement.kt index cf7262540..f3b4d9238 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/BitwiseComplement.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/BitwiseComplement.kt @@ -4,6 +4,7 @@ import it.unibo.tuprolog.core.Integer import it.unibo.tuprolog.core.Numeric import it.unibo.tuprolog.core.Real import it.unibo.tuprolog.solve.ExecutionContext +import it.unibo.tuprolog.solve.function.UnaryMathFunction /** * Implementation of `'\'/1` arithmetic functor diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/BitwiseLeftShift.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/BitwiseLeftShift.kt index 9627523c0..3a21252c3 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/BitwiseLeftShift.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/BitwiseLeftShift.kt @@ -3,6 +3,7 @@ package it.unibo.tuprolog.solve.stdlib.function import it.unibo.tuprolog.core.Integer import it.unibo.tuprolog.core.Numeric import it.unibo.tuprolog.solve.ExecutionContext +import it.unibo.tuprolog.solve.function.IntegersBinaryMathFunction /** * Implementation of `'<<'/2` arithmetic functor diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/BitwiseOr.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/BitwiseOr.kt index 0ea331c81..d05221d78 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/BitwiseOr.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/BitwiseOr.kt @@ -3,6 +3,7 @@ package it.unibo.tuprolog.solve.stdlib.function import it.unibo.tuprolog.core.Integer import it.unibo.tuprolog.core.Numeric import it.unibo.tuprolog.solve.ExecutionContext +import it.unibo.tuprolog.solve.function.IntegersBinaryMathFunction /** * Implementation of `'\/'/2` arithmetic functor diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/BitwiseRightShift.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/BitwiseRightShift.kt index ad694c524..4e8965ca8 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/BitwiseRightShift.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/BitwiseRightShift.kt @@ -3,6 +3,7 @@ package it.unibo.tuprolog.solve.stdlib.function import it.unibo.tuprolog.core.Integer import it.unibo.tuprolog.core.Numeric import it.unibo.tuprolog.solve.ExecutionContext +import it.unibo.tuprolog.solve.function.IntegersBinaryMathFunction /** * Implementation of `'>>'/2` arithmetic functor diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/Ceiling.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/Ceiling.kt index f7832fe86..fb54cbf85 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/Ceiling.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/Ceiling.kt @@ -4,6 +4,7 @@ import it.unibo.tuprolog.core.Integer import it.unibo.tuprolog.core.Numeric import it.unibo.tuprolog.core.Real import it.unibo.tuprolog.solve.ExecutionContext +import it.unibo.tuprolog.solve.function.UnaryMathFunction import kotlin.math.ceil /** diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/Cosine.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/Cosine.kt index ac8b77621..9709d9bbd 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/Cosine.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/Cosine.kt @@ -4,6 +4,7 @@ import it.unibo.tuprolog.core.Integer import it.unibo.tuprolog.core.Numeric import it.unibo.tuprolog.core.Real import it.unibo.tuprolog.solve.ExecutionContext +import it.unibo.tuprolog.solve.function.UnaryMathFunction import org.gciatto.kt.math.BigDecimal import kotlin.math.cos diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/Exponential.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/Exponential.kt index 30c5e3944..515c787ec 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/Exponential.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/Exponential.kt @@ -4,6 +4,7 @@ import it.unibo.tuprolog.core.Integer import it.unibo.tuprolog.core.Numeric import it.unibo.tuprolog.core.Real import it.unibo.tuprolog.solve.ExecutionContext +import it.unibo.tuprolog.solve.function.UnaryMathFunction import org.gciatto.kt.math.BigDecimal import kotlin.math.exp diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/Exponentiation.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/Exponentiation.kt index 7271b38ed..3540061ba 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/Exponentiation.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/Exponentiation.kt @@ -4,6 +4,7 @@ import it.unibo.tuprolog.core.Integer import it.unibo.tuprolog.core.Numeric import it.unibo.tuprolog.core.Real import it.unibo.tuprolog.solve.ExecutionContext +import it.unibo.tuprolog.solve.function.BinaryMathFunction import org.gciatto.kt.math.BigDecimal import kotlin.math.pow diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/FloatFractionalPart.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/FloatFractionalPart.kt index c24a4deb5..08363f24f 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/FloatFractionalPart.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/FloatFractionalPart.kt @@ -4,6 +4,7 @@ import it.unibo.tuprolog.core.Integer import it.unibo.tuprolog.core.Numeric import it.unibo.tuprolog.core.Real import it.unibo.tuprolog.solve.ExecutionContext +import it.unibo.tuprolog.solve.function.UnaryMathFunction import org.gciatto.kt.math.BigDecimal import org.gciatto.kt.math.RoundingMode diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/FloatIntegerPart.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/FloatIntegerPart.kt index 1e3453dfb..1e0e29a9a 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/FloatIntegerPart.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/FloatIntegerPart.kt @@ -4,6 +4,7 @@ import it.unibo.tuprolog.core.Integer import it.unibo.tuprolog.core.Numeric import it.unibo.tuprolog.core.Real import it.unibo.tuprolog.solve.ExecutionContext +import it.unibo.tuprolog.solve.function.UnaryMathFunction import org.gciatto.kt.math.BigDecimal import org.gciatto.kt.math.RoundingMode diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/FloatingPointDivision.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/FloatingPointDivision.kt index a4fc796d6..978a15ad1 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/FloatingPointDivision.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/FloatingPointDivision.kt @@ -4,6 +4,7 @@ import it.unibo.tuprolog.core.Integer import it.unibo.tuprolog.core.Numeric import it.unibo.tuprolog.core.Real import it.unibo.tuprolog.solve.ExecutionContext +import it.unibo.tuprolog.solve.function.BinaryMathFunction import org.gciatto.kt.math.BigDecimal import org.gciatto.kt.math.MathContext diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/Floor.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/Floor.kt index 5225448e0..770f5898e 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/Floor.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/Floor.kt @@ -4,6 +4,7 @@ import it.unibo.tuprolog.core.Integer import it.unibo.tuprolog.core.Numeric import it.unibo.tuprolog.core.Real import it.unibo.tuprolog.solve.ExecutionContext +import it.unibo.tuprolog.solve.function.UnaryMathFunction import org.gciatto.kt.math.BigDecimal import org.gciatto.kt.math.RoundingMode diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/IntegerDivision.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/IntegerDivision.kt index 2301695e7..4af401e2e 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/IntegerDivision.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/IntegerDivision.kt @@ -3,6 +3,7 @@ package it.unibo.tuprolog.solve.stdlib.function import it.unibo.tuprolog.core.Integer import it.unibo.tuprolog.core.Numeric import it.unibo.tuprolog.solve.ExecutionContext +import it.unibo.tuprolog.solve.function.IntegersBinaryMathFunction import org.gciatto.kt.math.BigInteger /** diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/Modulo.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/Modulo.kt index 492748440..6e59ae7ba 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/Modulo.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/Modulo.kt @@ -3,6 +3,7 @@ package it.unibo.tuprolog.solve.stdlib.function import it.unibo.tuprolog.core.Integer import it.unibo.tuprolog.core.Numeric import it.unibo.tuprolog.solve.ExecutionContext +import it.unibo.tuprolog.solve.function.IntegersBinaryMathFunction import org.gciatto.kt.math.BigInteger /** diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/Multiplication.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/Multiplication.kt index 1b518fa0f..42b909152 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/Multiplication.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/Multiplication.kt @@ -4,6 +4,7 @@ import it.unibo.tuprolog.core.Integer import it.unibo.tuprolog.core.Numeric import it.unibo.tuprolog.core.Real import it.unibo.tuprolog.solve.ExecutionContext +import it.unibo.tuprolog.solve.function.BinaryMathFunction import org.gciatto.kt.math.BigDecimal /** diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/NaturalLogarithm.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/NaturalLogarithm.kt index 2012ed6af..b4c6d031e 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/NaturalLogarithm.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/NaturalLogarithm.kt @@ -4,6 +4,7 @@ import it.unibo.tuprolog.core.Integer import it.unibo.tuprolog.core.Numeric import it.unibo.tuprolog.core.Real import it.unibo.tuprolog.solve.ExecutionContext +import it.unibo.tuprolog.solve.function.UnaryMathFunction import org.gciatto.kt.math.BigDecimal import kotlin.math.E import kotlin.math.log diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/Remainder.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/Remainder.kt index 4e3891ce3..bf20a1c6f 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/Remainder.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/Remainder.kt @@ -3,6 +3,7 @@ package it.unibo.tuprolog.solve.stdlib.function import it.unibo.tuprolog.core.Integer import it.unibo.tuprolog.core.Numeric import it.unibo.tuprolog.solve.ExecutionContext +import it.unibo.tuprolog.solve.function.IntegersBinaryMathFunction import org.gciatto.kt.math.BigInteger /** diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/Round.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/Round.kt index 1d3912f05..7ee192685 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/Round.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/Round.kt @@ -4,6 +4,7 @@ import it.unibo.tuprolog.core.Integer import it.unibo.tuprolog.core.Numeric import it.unibo.tuprolog.core.Real import it.unibo.tuprolog.solve.ExecutionContext +import it.unibo.tuprolog.solve.function.UnaryMathFunction import org.gciatto.kt.math.BigDecimal import org.gciatto.kt.math.RoundingMode diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/Sign.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/Sign.kt index 580e66bba..d9fe77494 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/Sign.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/Sign.kt @@ -4,6 +4,7 @@ import it.unibo.tuprolog.core.Integer import it.unibo.tuprolog.core.Numeric import it.unibo.tuprolog.core.Real import it.unibo.tuprolog.solve.ExecutionContext +import it.unibo.tuprolog.solve.function.UnaryMathFunction /** * Implementation of `sign/1` arithmetic functor diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/SignReversal.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/SignReversal.kt index 15aedeb30..80c196f79 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/SignReversal.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/SignReversal.kt @@ -4,6 +4,7 @@ import it.unibo.tuprolog.core.Integer import it.unibo.tuprolog.core.Numeric import it.unibo.tuprolog.core.Real import it.unibo.tuprolog.solve.ExecutionContext +import it.unibo.tuprolog.solve.function.UnaryMathFunction /** * Implementation of `'-'/1` arithmetic functor diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/Sine.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/Sine.kt index b8b7249cf..279616304 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/Sine.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/Sine.kt @@ -4,6 +4,7 @@ import it.unibo.tuprolog.core.Integer import it.unibo.tuprolog.core.Numeric import it.unibo.tuprolog.core.Real import it.unibo.tuprolog.solve.ExecutionContext +import it.unibo.tuprolog.solve.function.UnaryMathFunction import org.gciatto.kt.math.BigDecimal import kotlin.math.sin diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/SquareRoot.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/SquareRoot.kt index c0410426c..394550044 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/SquareRoot.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/SquareRoot.kt @@ -4,6 +4,7 @@ import it.unibo.tuprolog.core.Integer import it.unibo.tuprolog.core.Numeric import it.unibo.tuprolog.core.Real import it.unibo.tuprolog.solve.ExecutionContext +import it.unibo.tuprolog.solve.function.UnaryMathFunction import org.gciatto.kt.math.BigDecimal /** diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/Subtraction.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/Subtraction.kt index 8aa27348e..e19180e6c 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/Subtraction.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/Subtraction.kt @@ -4,6 +4,7 @@ import it.unibo.tuprolog.core.Integer import it.unibo.tuprolog.core.Numeric import it.unibo.tuprolog.core.Real import it.unibo.tuprolog.solve.ExecutionContext +import it.unibo.tuprolog.solve.function.BinaryMathFunction import org.gciatto.kt.math.BigDecimal /** diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/ToFloat.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/ToFloat.kt index 604eb97d7..605a23937 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/ToFloat.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/ToFloat.kt @@ -4,6 +4,7 @@ import it.unibo.tuprolog.core.Integer import it.unibo.tuprolog.core.Numeric import it.unibo.tuprolog.core.Real import it.unibo.tuprolog.solve.ExecutionContext +import it.unibo.tuprolog.solve.function.UnaryMathFunction /** * Implementation of `float/1` arithmetic functor diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/Truncate.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/Truncate.kt index 373be854c..03f808e06 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/Truncate.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/function/Truncate.kt @@ -4,6 +4,7 @@ import it.unibo.tuprolog.core.Integer import it.unibo.tuprolog.core.Numeric import it.unibo.tuprolog.core.Real import it.unibo.tuprolog.solve.ExecutionContext +import it.unibo.tuprolog.solve.function.UnaryMathFunction import org.gciatto.kt.math.BigDecimal import org.gciatto.kt.math.RoundingMode diff --git a/test-solve/src/commonTest/kotlin/it/unibo/tuprolog/solve/stdlib/function/testutils/FunctionUtils.kt b/test-solve/src/commonTest/kotlin/it/unibo/tuprolog/solve/stdlib/function/testutils/FunctionUtils.kt index d5542147c..e4cf16d09 100644 --- a/test-solve/src/commonTest/kotlin/it/unibo/tuprolog/solve/stdlib/function/testutils/FunctionUtils.kt +++ b/test-solve/src/commonTest/kotlin/it/unibo/tuprolog/solve/stdlib/function/testutils/FunctionUtils.kt @@ -3,14 +3,14 @@ package it.unibo.tuprolog.solve.stdlib.function.testutils import it.unibo.tuprolog.core.Integer import it.unibo.tuprolog.core.Real import it.unibo.tuprolog.core.Term -import it.unibo.tuprolog.solve.stdlib.function.BinaryMathFunction -import it.unibo.tuprolog.solve.stdlib.function.UnaryMathFunction -import it.unibo.tuprolog.solve.Signature -import it.unibo.tuprolog.solve.function.Compute -import it.unibo.tuprolog.solve.function.FunctionWrapper import it.unibo.tuprolog.solve.DummyInstances import it.unibo.tuprolog.solve.ExecutionContext +import it.unibo.tuprolog.solve.Signature import it.unibo.tuprolog.solve.exception.error.TypeError +import it.unibo.tuprolog.solve.function.BinaryMathFunction +import it.unibo.tuprolog.solve.function.Compute +import it.unibo.tuprolog.solve.function.FunctionWrapper +import it.unibo.tuprolog.solve.function.UnaryMathFunction import kotlin.test.assertFailsWith /**