Skip to content

Commit 8b91c17

Browse files
committed
propagator model 中的 put 应该被改为 patch
1 parent c4c40fa commit 8b91c17

11 files changed

+70
-64
lines changed

src/belief/Belief.test.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import assert from "node:assert"
22
import { test } from "node:test"
3-
import { Cell, put } from "../cell/index.js"
3+
import { Cell, patch } from "../cell/index.js"
44
import { Interval, intervalAlmostEqual } from "../interval/index.js"
55
import { run } from "../scheduler/index.js"
66
import { Belief, beliefEqual, isBelief } from "./index.js"
@@ -15,9 +15,9 @@ test("dependency / a justified-intervals anomaly", async () => {
1515
// A,B,C: [ ]
1616

1717
const interval = Cell()
18-
put(interval, Belief(Interval(0, 100), ["A"]))
19-
put(interval, Belief(Interval(50, 200), ["B"]))
20-
put(interval, Belief(Interval(25, 75), ["C"]))
18+
patch(interval, Belief(Interval(0, 100), ["A"]))
19+
patch(interval, Belief(Interval(50, 200), ["B"]))
20+
patch(interval, Belief(Interval(25, 75), ["C"]))
2121

2222
await run()
2323

@@ -34,9 +34,9 @@ test("dependency / a justified-intervals anomaly", async () => {
3434
// The order matters.
3535

3636
const interval = Cell()
37-
put(interval, Belief(Interval(25, 75), ["C"]))
38-
put(interval, Belief(Interval(0, 100), ["A"]))
39-
put(interval, Belief(Interval(50, 200), ["B"]))
37+
patch(interval, Belief(Interval(25, 75), ["C"]))
38+
patch(interval, Belief(Interval(0, 100), ["A"]))
39+
patch(interval, Belief(Interval(50, 200), ["B"]))
4040

4141
await run()
4242

src/cell/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
export * from "./addPropagator.js"
22
export * from "./Cell.js"
3-
export * from "./put.js"
3+
export * from "./patch.js"

src/cell/put.ts renamed to src/cell/patch.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { merge } from "../merge/index.js"
22
import { schedule } from "../scheduler/index.js"
33
import { type Cell } from "./Cell.js"
44

5-
export function put<T>(cell: Cell<T>, increment?: any): void {
5+
export function patch<T>(cell: Cell<T>, increment?: any): void {
66
const newContent = merge(cell.content, increment)
77
if (newContent === cell.content) {
88
return

src/examples/barometer-belief-system.test.ts

+13-7
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
kickOut,
1010
} from "../belief-system/index.js"
1111
import { Belief, beliefEqual } from "../belief/index.js"
12-
import { Cell, put } from "../cell/index.js"
12+
import { Cell, patch } from "../cell/index.js"
1313
import { Interval, intervalAlmostEqual, isInterval } from "../interval/index.js"
1414
import { theMergeConflict } from "../merge-conflict/index.js"
1515
import { isNothing } from "../nothing/index.js"
@@ -25,9 +25,15 @@ test("examples / barometer-belief-system", async () => {
2525

2626
const [barometerShadow, barometerHeight, buildingShadow, buildingHeight] =
2727
similarTriangles()
28-
put(buildingShadow, BeliefSystem([Belief(Interval(54.9, 55.1), ["shadows"])]))
29-
put(barometerHeight, BeliefSystem([Belief(Interval(0.3, 0.32), ["shadows"])]))
30-
put(
28+
patch(
29+
buildingShadow,
30+
BeliefSystem([Belief(Interval(54.9, 55.1), ["shadows"])]),
31+
)
32+
patch(
33+
barometerHeight,
34+
BeliefSystem([Belief(Interval(0.3, 0.32), ["shadows"])]),
35+
)
36+
patch(
3137
barometerShadow,
3238
BeliefSystem([Belief(Interval(0.36, 0.37), ["shadows"])]),
3339
)
@@ -53,7 +59,7 @@ test("examples / barometer-belief-system", async () => {
5359

5460
const fallTime = Cell()
5561
fallDuration(fallTime, buildingHeight)
56-
put(fallTime, BeliefSystem([Belief(Interval(2.9, 3.1), ["fall-time"])]))
62+
patch(fallTime, BeliefSystem([Belief(Interval(2.9, 3.1), ["fall-time"])]))
5763

5864
await run()
5965

@@ -241,7 +247,7 @@ test("examples / barometer-belief-system", async () => {
241247
// Now, if we give the superintendent a barometer, we can add her
242248
// input to the totality of our knowledge about this building
243249

244-
put(buildingHeight, Belief(45, ["superintendent"]))
250+
patch(buildingHeight, Belief(45, ["superintendent"]))
245251

246252
await run()
247253

@@ -418,7 +424,7 @@ test("examples / barometer-belief-system", async () => {
418424
// know; and since the system maintains dependency information, it
419425
// can even tell us which premises lead to trouble.
420426

421-
put(buildingHeight, Belief(Interval(46, 50), ["pressure"]))
427+
patch(buildingHeight, Belief(Interval(46, 50), ["pressure"]))
422428

423429
await run()
424430

src/examples/barometer-belief.test.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
import assert from "node:assert"
22
import { test } from "node:test"
33
import { Belief, beliefEqual, isBelief } from "../belief/index.js"
4-
import { Cell, put } from "../cell/index.js"
4+
import { Cell, patch } from "../cell/index.js"
55
import { Interval, intervalAlmostEqual } from "../interval/index.js"
66
import { run } from "../scheduler/index.js"
77
import { fallDuration, similarTriangles } from "./barometer.js"
88

99
test("examples / barometer-belief", async () => {
1010
const [barometerShadow, barometerHeight, buildingShadow, buildingHeight] =
1111
similarTriangles()
12-
put(buildingShadow, Belief(Interval(54.9, 55.1), ["shadows"]))
13-
put(barometerHeight, Belief(Interval(0.3, 0.32), ["shadows"]))
14-
put(barometerShadow, Belief(Interval(0.36, 0.37), ["shadows"]))
12+
patch(buildingShadow, Belief(Interval(54.9, 55.1), ["shadows"]))
13+
patch(barometerHeight, Belief(Interval(0.3, 0.32), ["shadows"]))
14+
patch(barometerShadow, Belief(Interval(0.36, 0.37), ["shadows"]))
1515

1616
await run()
1717

@@ -28,7 +28,7 @@ test("examples / barometer-belief", async () => {
2828

2929
const fallTime = Cell()
3030
fallDuration(fallTime, buildingHeight)
31-
put(fallTime, Belief(Interval(2.9, 3.3), ["lousy-fall-time"]))
31+
patch(fallTime, Belief(Interval(2.9, 3.3), ["lousy-fall-time"]))
3232

3333
await run()
3434

@@ -50,7 +50,7 @@ test("examples / barometer-belief", async () => {
5050
),
5151
)
5252

53-
put(fallTime, Belief(Interval(2.9, 3.1), ["better-fall-time"]))
53+
patch(fallTime, Belief(Interval(2.9, 3.1), ["better-fall-time"]))
5454

5555
await run()
5656

@@ -65,7 +65,7 @@ test("examples / barometer-belief", async () => {
6565
),
6666
)
6767

68-
put(buildingHeight, Belief(45, ["superintendent"]))
68+
patch(buildingHeight, Belief(45, ["superintendent"]))
6969

7070
await run()
7171

@@ -130,7 +130,7 @@ test("examples / barometer-belief", async () => {
130130

131131
{
132132
const [t, h] = fallDuration()
133-
put(h, 45)
133+
patch(h, 45)
134134

135135
await run()
136136

src/examples/barometer.test.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import assert from "node:assert"
22
import { test } from "node:test"
3-
import { Cell, put } from "../cell/index.js"
3+
import { Cell, patch } from "../cell/index.js"
44
import { Interval, intervalAlmostEqual } from "../interval/index.js"
55
import { run } from "../scheduler/index.js"
66
import { fallDuration, similarTriangles } from "./barometer.js"
77

88
test("examples / barometer / fallDuration", async () => {
99
const [fallTime, buildingHeight] = fallDuration()
10-
put(fallTime, Interval(2.9, 3.1))
10+
patch(fallTime, Interval(2.9, 3.1))
1111

1212
await run()
1313

@@ -18,15 +18,15 @@ test("examples / barometer / fallDuration", async () => {
1818

1919
test("examples / barometer / fallDuration / Interval + Number", async () => {
2020
const [fallTime, buildingHeight] = fallDuration()
21-
put(fallTime, Interval(2.9, 3.1))
21+
patch(fallTime, Interval(2.9, 3.1))
2222

2323
await run()
2424

2525
assert(
2626
intervalAlmostEqual(buildingHeight.content, Interval(41.16, 47.24), 0.01),
2727
)
2828

29-
put(buildingHeight, 45)
29+
patch(buildingHeight, 45)
3030

3131
await run()
3232

@@ -36,9 +36,9 @@ test("examples / barometer / fallDuration / Interval + Number", async () => {
3636
test("examples / barometer / similarTriangles & fallDuration", async () => {
3737
const [barometerShadow, barometerHeight, buildingShadow, buildingHeight] =
3838
similarTriangles()
39-
put(buildingShadow, Interval(54.9, 55.1))
40-
put(barometerHeight, Interval(0.3, 0.32))
41-
put(barometerShadow, Interval(0.36, 0.37))
39+
patch(buildingShadow, Interval(54.9, 55.1))
40+
patch(barometerHeight, Interval(0.3, 0.32))
41+
patch(barometerShadow, Interval(0.36, 0.37))
4242

4343
await run()
4444

@@ -48,7 +48,7 @@ test("examples / barometer / similarTriangles & fallDuration", async () => {
4848

4949
const fallTime = Cell()
5050
fallDuration(fallTime, buildingHeight)
51-
put(fallTime, Interval(2.9, 3.1))
51+
patch(fallTime, Interval(2.9, 3.1))
5252

5353
await run()
5454

src/examples/celsius.test.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import assert from "node:assert"
22
import { test } from "node:test"
3-
import { put } from "../cell/index.js"
3+
import { patch } from "../cell/index.js"
44
import { run } from "../scheduler/index.js"
55
import {
66
celsiusKelvin,
@@ -10,7 +10,7 @@ import {
1010

1111
test("examples / celsius / fahrenheitToCelsius", async () => {
1212
const [f, c] = fahrenheitToCelsius()
13-
put(f, 77)
13+
patch(f, 77)
1414

1515
await run()
1616

@@ -20,7 +20,7 @@ test("examples / celsius / fahrenheitToCelsius", async () => {
2020
test("examples / celsius / fahrenheitCelsius", async () => {
2121
{
2222
const [f, c] = fahrenheitCelsius()
23-
put(f, 77)
23+
patch(f, 77)
2424

2525
await run()
2626

@@ -29,7 +29,7 @@ test("examples / celsius / fahrenheitCelsius", async () => {
2929

3030
{
3131
const [f, c] = fahrenheitCelsius()
32-
put(c, 25)
32+
patch(c, 25)
3333

3434
await run()
3535

@@ -40,7 +40,7 @@ test("examples / celsius / fahrenheitCelsius", async () => {
4040
test("examples / celsius / celsiusKelvin", async () => {
4141
const [f, c] = fahrenheitCelsius()
4242
const k = celsiusKelvin(c)
43-
put(f, 77)
43+
patch(f, 77)
4444

4545
await run()
4646

src/examples/heron.test.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import assert from "node:assert"
22
import { test } from "node:test"
3-
import { Cell, put } from "../cell/index.js"
3+
import { Cell, patch } from "../cell/index.js"
44
import { run } from "../scheduler/index.js"
55
import { heronStep } from "./heron.js"
66

77
test("examples / heron / heronStep", async () => {
88
const [x, guess, betterGuess] = heronStep()
9-
put(x, 2)
10-
put(guess, 1.4)
9+
patch(x, 2)
10+
patch(guess, 1.4)
1111

1212
await run()
1313

src/propagator/definePrimitive.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Cell, addPropagator, put } from "../cell/index.js"
1+
import { Cell, addPropagator, patch } from "../cell/index.js"
22
import { naryFmap } from "../monad/index.js"
33
import { schedule } from "../scheduler/index.js"
44
import type { MaybePromise } from "../utils/MaybePromise.js"
@@ -40,14 +40,14 @@ export function definePrimitive<A extends number>(
4040
const output = args[args.length - 1]
4141

4242
watch(inputs, async () => {
43-
put(output, await liftedFn(...inputs))
43+
patch(output, await liftedFn(...inputs))
4444
})
4545
} else if (args.length === arity - 1) {
4646
const inputs = args
4747
const output = Cell()
4848

4949
watch(inputs, async () => {
50-
put(output, await liftedFn(...inputs))
50+
patch(output, await liftedFn(...inputs))
5151
})
5252

5353
return output
@@ -57,7 +57,7 @@ export function definePrimitive<A extends number>(
5757
const output = Cell()
5858

5959
watch(inputs, async () => {
60-
put(output, await liftedFn(...inputs))
60+
patch(output, await liftedFn(...inputs))
6161
})
6262

6363
return [...paddings, output]

0 commit comments

Comments
 (0)