Skip to content

Commit

Permalink
Updated docs, renamed creating of wildcard
Browse files Browse the repository at this point in the history
  • Loading branch information
Damtev committed Sep 28, 2023
1 parent 553c8a4 commit d048635
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
7 changes: 2 additions & 5 deletions klogic-core/src/main/kotlin/org/klogic/core/Context.kt
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,10 @@ open class RelationalContext : AutoCloseable {
fun <T : Term<T>> freshTypedVar(): Var<T> = (lastCreatedVariableIndex++).createTypedVar()

/**
* Returns a new wildcard [Wildcard] of the specified type with [lastCreatedWildcardIndex] as its [Wildcard.index]
* and increments [lastCreatedWildcardIndex].
*
* NOTE: this method is not thread-safe and requires explicit outer synchronization in multithreading applications.
* Returns a new [Wildcard] according to the specified type.
*/
@Suppress("UNCHECKED_CAST")
fun <T : Term<T>> freshTypedWildcard(): Term<T> = Wildcard as T
fun <T : Term<T>> wildcard(): Term<T> = Wildcard as T

/**
* Returns a result of invoking [run] overloading with goals for the fresh variable created using the passed [state].
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class WildcardsTest {
@Test
fun `x !== __ -- failure`() {
withEmptyContext {
val goal = { x: Term<Symbol> -> x `!==` freshTypedWildcard() }
val goal = { x: Term<Symbol> -> x `!==` wildcard() }

val run = run(10, goal)
assertTrue(run.isEmpty())
Expand All @@ -42,7 +42,7 @@ class WildcardsTest {
val one = "1".toSymbol()

fun goal(x: Term<LogicPair<Symbol, Symbol>>, y: Term<Symbol>): Goal =
(x `!==` (freshTypedWildcard<Symbol>() logicTo one)) and (x `===` (one logicTo y))
(x `!==` (wildcard<Symbol>() logicTo one)) and (x `===` (one logicTo y))

val y = freshTypedVar<Symbol>()
val x = freshTypedVar<LogicPair<Symbol, Symbol>>()
Expand All @@ -66,7 +66,7 @@ class WildcardsTest {
withEmptyContext {
val one = "1".toSymbol()

val goal = { _: Term<*> -> (one logicTo freshTypedWildcard<Symbol>()) `!==` (freshTypedWildcard<Symbol>() logicTo one) }
val goal = { _: Term<*> -> (one logicTo wildcard<Symbol>()) `!==` (wildcard<Symbol>() logicTo one) }

val run = run(10, goal)
assertTrue(run.isEmpty())
Expand All @@ -80,7 +80,7 @@ class WildcardsTest {
val two = "2".toSymbol()

val goal = { x: Term<Symbol> ->
logicListOf(x, two, freshTypedWildcard()) `!==` logicListOf(one, freshTypedWildcard(), two)
logicListOf(x, two, wildcard()) `!==` logicListOf(one, wildcard(), two)
}

val run = run(10, goal)
Expand All @@ -105,7 +105,7 @@ class WildcardsTest {
val x = freshTypedVar<Symbol>()
val y = freshTypedVar<Symbol>()
val goal = { symbol: Term<Symbol> ->
logicListOf(symbol, y) `!==` logicListOf(one, freshTypedWildcard())
logicListOf(symbol, y) `!==` logicListOf(one, wildcard())
}

val run = run(10, x, goal(x))
Expand All @@ -132,7 +132,7 @@ class WildcardsTest {
}
)

fun lessThan4(x: Term<PeanoLogicNumber>) = x `!==` +(+(+(+(freshTypedWildcard<PeanoLogicNumber>()))))
fun lessThan4(x: Term<PeanoLogicNumber>) = x `!==` +(+(+(+(wildcard<PeanoLogicNumber>()))))

val goal = { x: Term<PeanoLogicNumber> -> lessThan4(x) and allPeanoNumbers(x) }

Expand All @@ -157,7 +157,7 @@ class WildcardsTest {
}
)

fun isNotCons(x: Term<LogicList<Symbol>>) = x `!==` Cons(freshTypedWildcard(), freshTypedWildcard())
fun isNotCons(x: Term<LogicList<Symbol>>) = x `!==` Cons(wildcard(), wildcard())

val goal = { x: Term<LogicList<Symbol>> -> isNotCons(x) and allLists(x) }

Expand Down

0 comments on commit d048635

Please sign in to comment.