-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
…#2271) Since Swarm is strict, the way an application `instant c` works is as follows: 1. Evaluate the LHS `instant` to a value (immediately succeeds since it is just a constant) 2. Evaluate the RHS `c` to a value 3. Perform the function application `instant c`, by atomically executing the command represented by `c` Usually, step (2) succeeds almost instantly as well. For example if `c` is something like `move; move; turn right; move` then it just instantly turns into a command value. However, `c` could be something like `def x = (expensive pure expression) end; other stuff` in which case evaluating `c` will cause the definition of `x` to be (expensively) evaluated. This PR rectifies the situation by ensuring that not only are `instant`/`atomic` *executed* atomically, but also their argument is *evaluated* atomically. Fixes #2270.
- Loading branch information
Showing
5 changed files
with
78 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
version: 1 | ||
name: Instant wrapped defs | ||
description: | | ||
`instant` should work when wrapped around definitions | ||
creative: false | ||
objectives: | ||
- goal: | ||
- Grab the rock | ||
condition: | | ||
as base { has "rock" } | ||
robots: | ||
- name: base | ||
dir: east | ||
devices: | ||
- logger | ||
- treads | ||
- grabber | ||
- name: judge | ||
dir: east | ||
system: true | ||
program: | | ||
instant ( | ||
def fib : Int -> Int = \n. | ||
if (n <= 1) {n} {fib (n-1) + fib (n-2)} | ||
end | ||
def x = fib 10 end | ||
create "rock"; place "rock" | ||
) | ||
solution: | | ||
move; grab | ||
known: [rock] | ||
world: | ||
dsl: | | ||
{grass} | ||
palette: | ||
'B': [grass, null, base] | ||
'j': [grass, null, judge] | ||
upperleft: [0, 0] | ||
map: | | ||
Bj |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters