Skip to content

Commit 9a75949

Browse files
authored
Give instant and atomic types {Cmd a} -> Cmd a (#2552)
This is an alternative, better solution to #2270, which allows us to delete the special-case code added in #2271. By delaying the argument to `instant` and `atomic`, it will be evaluated at execution time (and thus happen atomically) rather than before. Closes #2521.
1 parent e5dfb5f commit 9a75949

File tree

36 files changed

+96
-123
lines changed

36 files changed

+96
-123
lines changed

data/entities.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1144,7 +1144,7 @@
11441144
- "To prevent this situation, robot A can wrap the commands in `atomic`, like so:"
11451145
- |
11461146
```
1147-
atomic (b <- ishere "rock"; if b {grab; pure ()} {})
1147+
atomic {b <- ishere "rock"; if b {grab; pure ()} {}}
11481148
```
11491149
properties: [pickable]
11501150
capabilities: [atomic]

data/scenarios/Challenges/Ranching/_beekeeping/queenbee.sw

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ def observeHives =
247247
end;
248248

249249
def go =
250-
instant $ observeHives;
250+
instant {observeHives};
251251
end;
252252

253253
go;

data/scenarios/Challenges/Ranching/_capture/opponent.sw

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,14 @@ def reWatch =
6060
end;
6161

6262
def reWatchEntities = \instantCont.
63-
s1 <- instant (
63+
s1 <- instant {
6464
forDirs (\d. watch d; scan d)
65-
);
65+
};
6666
wait 10000;
67-
instant (
67+
instant {
6868
s2 <- forDirs scan;
6969
if (s1 != s2) {instantCont} {}
70-
);
70+
};
7171
reWatchEntities instantCont
7272
end
7373

data/scenarios/Challenges/Ranching/_fishing/hauler.sw

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def turnAround = \d.
5151

5252
def waitUntilEnclosureFull =
5353

54-
isFull <- instant isEitherEnclosureFull;
54+
isFull <- instant {isEitherEnclosureFull};
5555
if isFull {
5656
// Drive down the road
5757
turn south;

data/scenarios/Challenges/Ranching/_powerset/setup.sw

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ def waitForFirstPlacement =
241241
end;
242242

243243
def go = \distinctCount.
244-
exclusionValue <- instant $ setup distinctCount;
244+
exclusionValue <- instant {setup distinctCount};
245245
give base "bell";
246246

247247
waitForFirstPlacement;

data/scenarios/Challenges/Sliding Puzzles/_sliding-puzzle/maintainer.sw

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,15 +194,15 @@ def watchBoard =
194194
def go = \boardWidth. \boardHeight.
195195

196196
// Re-position at the bottom-left corner
197-
instant $ atLocation (0, -(boardHeight - 1)) (
197+
instant { atLocation (0, -(boardHeight - 1)) (
198198
handleMarker boardWidth boardHeight;
199199

200200
// NOTE: I originally intended to use 'watch' as a performance optimization.
201201
// Hoewver, Using 'watch' seems to incur some lag in the 'maintainer' bot's reaction
202202
// such that the player is not replentished with 'ink' by the time they might
203203
// want to perform their next 'drill' operation.
204204
// watchBoard;
205-
);
205+
)};
206206

207207
// Throttle the recursion, otherwise it will max out the allowed operations per tick
208208
wait 1;

data/scenarios/Challenges/Sliding Puzzles/_sliding-puzzle/setup.sw

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ def setupGame = \boardWidth. \boardHeight.
293293
end;
294294

295295
def go = \boardWidth. \boardHeight.
296-
instant $ setupGame boardWidth boardHeight;
296+
instant {setupGame boardWidth boardHeight};
297297
end;
298298

299299
go 3 3;

data/scenarios/Challenges/_combo-lock/setup.sw

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,12 @@ def createCombo = \colorString.
7373
end;
7474

7575
def go =
76-
comboString <- instant (
76+
comboString <- instant {
7777
move;
7878
createCombo "";
79-
);
79+
};
8080
// say comboString;
81-
instant $ doUntilCorrect comboString;
81+
instant {doUntilCorrect comboString};
8282
end;
8383

8484
go;

data/scenarios/Challenges/_dna/lab.sw

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def placeBase = \standbyFunc. \n.
114114
clonedOrganism <- placeBase standbyFunc $ n - 1;
115115

116116
// Unwinds the stack; verifies the original placement order
117-
placedEnt <- instant waitUntilSomethingExists;
117+
placedEnt <- instant {waitUntilSomethingExists};
118118
let isGood = ent == placedEnt in
119119
move;
120120

@@ -139,7 +139,7 @@ def makeDnaStrand = \receptacleLoc.
139139
case eitherClonedOrganism (\_.
140140
create "pixel (R)";
141141
) (\clonedItem.
142-
instant $ (
142+
instant {
143143
teleport self (0, -11);
144144
waitUntilHere "switch (on)";
145145

@@ -155,13 +155,13 @@ def makeDnaStrand = \receptacleLoc.
155155
create slideBox;
156156
give base slideBox;
157157
say $ "You got a new \"" ++ slideBox ++ "\"";
158-
);
158+
};
159159
);
160160
end;
161161

162162
def waitForCloneableOrganism =
163163
let receptacleLoc = waypointByIndex "receiver" 0 in
164-
organism <- instant (
164+
organism <- instant {
165165
teleport self receptacleLoc;
166166

167167
waitUntilOccupied;
@@ -170,7 +170,7 @@ def waitForCloneableOrganism =
170170
pure $ case thingHere (\x. inL x) (\item.
171171
if (hastag item "organism") {inR item} {inL ()}
172172
)
173-
);
173+
};
174174

175175
case organism (\_.
176176
say "Not a cloneable organism!";

data/scenarios/Challenges/_dna/mirrorbot.sw

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def waitUntilEmpty =
9191
end;
9292

9393
def go =
94-
instant waitUntilHere;
94+
instant {waitUntilHere};
9595
waitUntilEmpty;
9696
go;
9797
end;

0 commit comments

Comments
 (0)