-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathdouble2.yaml
57 lines (57 loc) · 1.26 KB
/
double2.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
name: double2
doc: |-
A machine that double numbers and protests requests for doubling non-numbers.
patternsyntax: json
nodes:
start:
branching:
branches:
- target: listen
listen:
branching:
type: message
branches:
- pattern: |
{"double":"?x"}
guard:
interpreter: ecmascript
source: |-
var bs = _.bindings;
var f = parseFloat(bs["?x"]);
if (isNaN(f)) {
return null;
} else {
bs["?x"] = f; // Overwrite with the number.
return bs;
}
target: double
- pattern: |
{"double": "?x"}
target: complain
double:
action:
interpreter: ecmascript
source: |-
_.out({doubled: _.bindings["?x"]*2});
return _.bindings;
branching:
branches:
- target: cleanup
complain:
action:
interpreter: ecmascript
source: |-
_.out({bad: _.bindings["?x"]});
return _.bindings;
branching:
branches:
- target: cleanup
cleanup:
action:
interpreter: ecmascript
source: |-
delete _.bindings["?x"];
return _.bindings;
branching:
branches:
- target: listen