Skip to content

Commit

Permalink
checkConsistent
Browse files Browse the repository at this point in the history
  • Loading branch information
xieyuheng committed Sep 5, 2024
1 parent 034b7be commit 7b7ceaf
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 3 deletions.
4 changes: 2 additions & 2 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
`MergeConflict` 移至 `merge-conflict/` -- 正与 `nothing/` 相同

`barometer-belief.test` -- 在测试中增加书中的叙述 -- 与对 belief-system 的测试相同

# 4.3 Dependencies Explain Contradictions

> https://github.com/cicada-lang/propagator/issues/9
`MergeConflict` 移至 `merge-conflict/` -- 正与 `nothing/` 相同

# 4.4 Dependencies Improve Search

> https://github.com/cicada-lang/propagator/issues/4
Expand Down
2 changes: 2 additions & 0 deletions src/belief-system/beliefSystemMerge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { type MergeConflict } from "../merge/index.js"
import { assimilateBelief } from "./assimilateBelief.js"
import { assimilateBeliefSystem } from "./assimilateBeliefSystem.js"
import { BeliefSystem } from "./BeliefSystem.js"
import { checkConsistent } from "./checkConsistent.js"
import { strongestBelief } from "./strongestBelief.js"

// Asking the belief system to deduce all the consequences of all its
Expand All @@ -16,5 +17,6 @@ export function beliefSystemMerge<A, B>(
): BeliefSystem<A | B> | MergeConflict {
const candidate = assimilateBeliefSystem(content, increment)
const consequence = strongestBelief(candidate.beliefs)
checkConsistent(consequence)
return assimilateBelief(candidate, consequence)
}
4 changes: 3 additions & 1 deletion src/belief-system/beliefSystemQuery.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import type { Belief } from "../belief/index.js"
import { type Belief } from "../belief/index.js"
import type { Nothing } from "../nothing/Nothing.js"
import type { BeliefSystem } from "./BeliefSystem.js"
import { assimilateBelief } from "./assimilateBelief.js"
import { checkConsistent } from "./checkConsistent.js"
import { strongestBelief } from "./strongestBelief.js"

export function beliefSystemQuery<A>(
Expand All @@ -13,5 +14,6 @@ export function beliefSystemQuery<A>(
beliefSystem.beliefs = betterBeliefSystem.beliefs
}

checkConsistent(answer)
return answer
}
12 changes: 12 additions & 0 deletions src/belief-system/checkConsistent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { detectMergeConflict } from "../merge/detectMergeConflict.js"
import { clearScheduledPropagators } from "../scheduler/schedule.js"
import { log } from "../utils/log.js"

export function checkConsistent(value: any): void {
if (detectMergeConflict(value)) {
const who = "checkConsistent"
const message = "inconsistent value"
log({ who, message, value })
clearScheduledPropagators()
}
}
13 changes: 13 additions & 0 deletions src/belief/beliefCheckConsistent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { detectMergeConflict } from "../merge/detectMergeConflict.js"
import { clearScheduledPropagators } from "../scheduler/schedule.js"
import { log } from "../utils/log.js"
import type { Belief } from "./Belief.js"

export function beliefCheckConsistent<A>(belief: Belief<A>): void {
if (detectMergeConflict(belief)) {
const who = "beliefCheckConsistent"
const message = "inconsistent belief"
log({ who, message, belief })
clearScheduledPropagators()
}
}
1 change: 1 addition & 0 deletions src/belief/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from "./Belief.js"
export * from "./beliefCheckConsistent.js"
export * from "./beliefEqual.js"
export * from "./beliefMerge.js"

0 comments on commit 7b7ceaf

Please sign in to comment.