Skip to content

Commit ab1541b

Browse files
authored
Merge pull request #161 from FolkComputer/ac/commit-to-hold
Replace all occurrences of "Commit" with "Hold"
2 parents b8329e5 + 3ef9727 commit ab1541b

File tree

12 files changed

+77
-69
lines changed

12 files changed

+77
-69
lines changed

README.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ created. Therefore, it will eventually be useful for you to know
329329
syntax](https://www.ee.columbia.edu/~shane/projects/sensornet/part1.pdf).
330330

331331
These are all implemented in `main.tcl`. For most things, you'll
332-
probably only need `Wish`, `Claim`, `When`, and maybe `Commit`.
332+
probably only need `Wish`, `Claim`, `When`, and maybe `Hold`.
333333

334334
### Wish and Claim
335335

@@ -428,25 +428,25 @@ cool`.
428428
first-class object. You can use `&` joins in that pattern as
429429
well.)
430430

431-
### Commit
431+
### Hold
432432

433-
Experimental: `Commit` is used to register claims that will stick
434-
around until you do another `Commit`. You can use this to create the
433+
Experimental: `Hold` is used to register claims that will stick
434+
around until you do another `Hold`. You can use this to create the
435435
equivalent of 'variables', stateful statements.
436436

437437
```
438-
Commit { Claim $this has a ball at x 100 y 100 }
438+
Hold { Claim $this has a ball at x 100 y 100 }
439439
440440
When $this has a ball at x /x/ y /y/ {
441441
puts "ball at $x $y"
442442
After 10 milliseconds {
443-
Commit { Claim $this has a ball at x $x y [expr {$y+1}] }
443+
Hold { Claim $this has a ball at x $x y [expr {$y+1}] }
444444
if {$y > 115} { set ::done true }
445445
}
446446
}
447447
```
448448

449-
`Commit` will overwrite all statements made by the previous `Commit`
449+
`Hold` will overwrite all statements made by the previous `Hold`
450450
(scoped to the current `$this`).
451451

452452
**Notice that you should scope your claim: it's `$this has a ball`, not `there
@@ -459,13 +459,13 @@ If you want multiple state atoms, you can also provide a key -- you
459459
can be like
460460

461461
```
462-
Commit ball position {
462+
Hold ball position {
463463
Claim $this has a ball at blahblah
464464
}
465465
```
466466

467-
and then future commits with that key, `ball position`, will
468-
overwrite this statement but not override different commits with
467+
and then future holds with that key, `ball position`, will
468+
overwrite this statement but not override different holds with
469469
different keys
470470

471471
(there's currently no way to overwrite state from other pages, but we
@@ -475,24 +475,24 @@ that if it was useful.)
475475
### Every time
476476

477477
Experimental: `Every time` works almost like `When`, but it's used to
478-
commit when an 'event' happens without causing a reaction cascade.
478+
hold when an 'event' happens without causing a reaction cascade.
479479

480480
**You can't make Claims, Whens, or Wishes inside an `Every time`
481-
block. You can only Commit.**
481+
block. You can only Hold.**
482482

483483
Example:
484484

485485
```
486-
Commit { Claim $this has seen 0 boops }
486+
Hold { Claim $this has seen 0 boops }
487487
488488
Every time there is a boop & $this has seen /n/ boops {
489-
Commit { Claim $this has seen [expr {$n + 1}] boops }
489+
Hold { Claim $this has seen [expr {$n + 1}] boops }
490490
}
491491
```
492492

493493
If you had used `When` here, it wouldn't terminate, since the new
494-
`$this has seen n+1 boops` commit would cause the `When` to retrigger,
495-
resulting in a `$this has seen n+2 boops` commit, then another
494+
`$this has seen n+1 boops` hold would cause the `When` to retrigger,
495+
resulting in a `$this has seen n+2 boops` hold, then another
496496
retrigger, and so on.
497497

498498
`Every time`, in contrast, will 'only react once' to the boop; nothing

lib/folk.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,9 +250,9 @@ class FolkWS {
250250
await this.evaluate(tcl`Assert when websocket $chan is connected [list {this __seq} ${message}] with environment [list $chan [incr ::__seq]]`);
251251
}
252252
// Evaluates inside a persistent match context that replaces any
253-
// previous commit with same key:
254-
async commit(key, program) {
255-
await this.evaluate(tcl`Commit (non-capturing) (on $chan) ${key} ${program}`);
253+
// previous hold with same key:
254+
async hold(key, program) {
255+
await this.evaluate(tcl`Hold (non-capturing) (on $chan) ${key} ${program}`);
256256
}
257257

258258
async watchCollected(statement, onChange) {

main.tcl

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,9 @@ proc After {n unit body} {
183183
}]] {*}$argValues]
184184
} else { error }
185185
}
186-
set ::committed [dict create]
187-
set ::toCommit [dict create]
188-
proc Commit {args} {
186+
set ::held [dict create]
187+
set ::toHold [dict create]
188+
proc Hold {args} {
189189
set this [uplevel {expr {[info exists this] ? $this : "<unknown>"}}]
190190
set key [list]
191191
set body [lindex $args end]
@@ -201,10 +201,10 @@ proc Commit {args} {
201201
lappend key $arg
202202
}
203203
}
204-
set key [list Commit $this {*}$key]
204+
set key [list Hold $this {*}$key]
205205

206206
if {$body eq ""} {
207-
dict set ::toCommit $key $body
207+
dict set ::toHold $key $body
208208
} else {
209209
if {$isNonCapturing} {
210210
set argNames {}
@@ -213,10 +213,18 @@ proc Commit {args} {
213213
lassign [uplevel Evaluator::serializeEnvironment] argNames argValues
214214
}
215215
set lambda [list {this} [list apply [list $argNames $body] {*}$argValues]]
216-
dict set ::toCommit $key $lambda
216+
dict set ::toHold $key $lambda
217217
}
218218
}
219219

220+
proc Commit {args} {
221+
set this [uplevel {expr {[info exists this] ? $this : "<unknown>"}}]
222+
set w "Commit was deprecated in July 2024; use Hold instead"
223+
Claim $this has warning $w with info $w
224+
225+
uplevel [list Hold {*}$args]
226+
}
227+
220228
set ::stepCount 0
221229
set ::stepTime -1
222230
source "lib/peer.tcl"
@@ -228,22 +236,22 @@ proc StepImpl {} {
228236
# Receive statements from all peers.
229237
foreach peerNs [namespace children ::Peers] {
230238
upvar ${peerNs}::process peer
231-
Commit $peer [list Say $peer is sharing statements [${peerNs}::receive]]
239+
Hold $peer [list Say $peer is sharing statements [${peerNs}::receive]]
232240
}
233241

234-
while {[dict size $::toCommit] > 0 || ![Evaluator::LogIsEmpty]} {
235-
dict for {key lambda} $::toCommit {
242+
while {[dict size $::toHold] > 0 || ![Evaluator::LogIsEmpty]} {
243+
dict for {key lambda} $::toHold {
236244
if {$lambda ne ""} {
237245
Assert $key has program $lambda
238246
}
239-
if {[dict exists $::committed $key] && [dict get $::committed $key] ne $lambda} {
240-
Retract $key has program [dict get $::committed $key]
247+
if {[dict exists $::held $key] && [dict get $::held $key] ne $lambda} {
248+
Retract $key has program [dict get $::held $key]
241249
}
242250
if {$lambda ne ""} {
243-
dict set ::committed $key $lambda
251+
dict set ::held $key $lambda
244252
}
245253
}
246-
set ::toCommit [dict create]
254+
set ::toHold [dict create]
247255
Evaluator::Evaluate
248256
}
249257

@@ -296,7 +304,7 @@ source "lib/math.tcl"
296304

297305

298306
# this defines $this in the contained scopes
299-
# it's also used to implement Commit
307+
# it's also used to implement Hold
300308
Assert when /this/ has program /__program/ {{this __program} {
301309
apply $__program $this
302310
}}

test/commit.tcl renamed to test/hold.tcl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
Assert programBall has program {{this} {
2-
Commit { Claim $this has a ball at x 100 y 100 }
2+
Hold { Claim $this has a ball at x 100 y 100 }
33

44
When $this has a ball at x /x/ y /y/ {
55
After 10 milliseconds {
6-
Commit { Claim $this has a ball at x $x y [expr {$y+1}] }
6+
Hold { Claim $this has a ball at x $x y [expr {$y+1}] }
77
if {$y > 115} { set ::done true }
88
}
99
}
@@ -15,10 +15,10 @@ vwait ::done
1515
Retract programBall has program /something/
1616

1717
Assert programUpdate has program {{this} {
18-
Commit { Claim $this has seen 0 boops }
18+
Hold { Claim $this has seen 0 boops }
1919

2020
Every time there is a boop & $this has seen /n/ boops {
21-
Commit { Claim $this has seen [expr {$n + 1}] boops }
21+
Hold { Claim $this has seen [expr {$n + 1}] boops }
2222
}
2323
}}
2424
Assert there is a boop
@@ -36,9 +36,9 @@ assert {[dict get [lindex [Statements::findMatches [list /someone/ claims /thing
3636

3737
Assert programTestReset has program {{this} {
3838
When $this has context color /color/ {
39-
Commit { Claim $this has counter 0 }
39+
Hold { Claim $this has counter 0 }
4040
Every time a button is pressed & $this has counter /counter/ {
41-
Commit { Claim $this has counter [incr counter] }
41+
Hold { Claim $this has counter [incr counter] }
4242
}
4343
}
4444
}}

test/stale.tcl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
for {set i 0} {$i < 30000} {incr i} {
2-
Commit [list Claim the iteration count is $i]
2+
Hold [list Claim the iteration count is $i]
33
Step
44
}
55

test/survival.tcl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ Assert when we are running {{} {
1414
Assert we are running
1515
Step
1616

17-
Commit Omar { Claim tag 1 was seen by Omar at home }
18-
Commit Mom { Claim tag 1 was seen by Mom at restaurant }
17+
Hold Omar { Claim tag 1 was seen by Omar at home }
18+
Hold Mom { Claim tag 1 was seen by Mom at restaurant }
1919
Step
2020

21-
Commit Omar { Claim tag 1 was seen by Omar at work }
21+
Hold Omar { Claim tag 1 was seen by Omar at work }
2222
Step
2323

2424
# Statements::print

user-programs/haippi7/laser-camera.folk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ On process {
2323
set tags [::BlobDetect::detect $grayFrame $threshold]
2424
}]
2525

26-
Commit {
26+
Hold {
2727
Claim the camera frame is $grayFrame
2828

2929
Claim the camera time is $cameraTime

virtual-programs/camera.folk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ Start process "camera" {
378378
set ::oldFrames [list]
379379
When $::thisProcess has step count /c/ {
380380
set frame [Camera::grayFrame]
381-
Commit {
381+
Hold {
382382
Claim the camera time is $::stepTime
383383
Claim the camera frame is $frame at [clock milliseconds]
384384
}

virtual-programs/display.folk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1684,7 +1684,7 @@ Start-display-process {
16841684
}]
16851685
if {$macos} { Gpu::poll }
16861686

1687-
Commit { Claim the display time is "render $renderTime us ($::stepTime)" }
1687+
Hold { Claim the display time is "render $renderTime us ($::stepTime)" }
16881688
}
16891689
}
16901690

0 commit comments

Comments
 (0)