Fix remaining Reactor usage in example programs.
Chris Pressey
5 years ago
0 | ;''FIXME -- uses old (Robin 0.2) Reactor syntax, not expected to work under 0.3'' | |
1 | ||
2 | ;(require small list arith) | |
0 | ;''Requires stdlib.'' | |
3 | 1 | |
4 | 2 | (reactor (line-terminal) (list 0 0) (macro (self args env) |
5 | 3 | (let ((event (head args)) |
6 | (payload (head (tail args))) | |
7 | (state (head (tail (tail args)))) | |
4 | (event-type (head event)) | |
5 | (event-payload (head (tail event))) | |
6 | (state (head (tail args))) | |
8 | 7 | (x (head state)) |
9 | 8 | (y (head (tail state))) |
10 | 9 | (move (fun (msg dx dy state) |
21 | 20 | (list state (list (literal writeln) |
22 | 21 | (literal ''Please enter n, s, e, or w, or q to quit.'')))))) |
23 | 22 | (choose |
24 | ((equal? event (literal init)) | |
23 | ((equal? event-type (literal init)) | |
25 | 24 | (list state (list (literal writeln) |
26 | 25 | (literal ''Welcome to Not Quite an Adventure!'')))) |
27 | ((equal? event (literal eof)) | |
26 | ((equal? event-type (literal eof)) | |
28 | 27 | (list state (list (literal writeln) |
29 | 28 | (literal ''Bye!'')))) |
30 | ((equal? event (literal readln)) | |
31 | (if (empty? payload) | |
29 | ((equal? event-type (literal readln)) | |
30 | (if (empty? event-payload) | |
32 | 31 | (dont-understand state) |
33 | (bind letter (list (head payload)) | |
32 | (bind letter (list (head event-payload)) | |
34 | 33 | (choose |
35 | 34 | ((equal? letter (literal ''n'')) |
36 | 35 | (move (literal ''North!'') 0 1 state)) |
41 | 40 | ((equal? letter (literal ''w'')) |
42 | 41 | (move (literal ''West!'') (subtract 0 1) 0 state)) |
43 | 42 | ((equal? letter (literal ''q'')) |
44 | (list state (list (literal close) 0))) | |
43 | (list state (list (literal stop) 0))) | |
45 | 44 | (else |
46 | 45 | (dont-understand state)))))) |
47 | 46 | (else |
0 | ;''FIXME -- uses old (Robin 0.2) Reactor syntax, not expected to work under 0.3'' | |
1 | ||
2 | (reactor (line-terminal) 0 (macro (self args env) | |
3 | (bind event (head args) | |
4 | (bind payload (head (tail args)) | |
5 | (if (equal? event (literal readln)) | |
6 | (list 0 (list (literal writeln) payload)) | |
7 | (list 0)))))) | |
0 | (reactor (line-terminal) 0 | |
1 | (macro (self args env) | |
2 | (bind event (head args) | |
3 | (bind event-type (head event) | |
4 | (bind event-payload (head (tail event)) | |
5 | (if (equal? event-type (literal readln)) | |
6 | (list 0 | |
7 | (list (literal writeln) event-payload)) | |
8 | (list 0))))))) |
0 | ;''FIXME -- uses old (Robin 0.2) Reactor syntax, not expected to work under 0.3'' | |
1 | ||
2 | (define inc (fun (a) (subtract a (subtract 0 1)))) | |
3 | (reactor (line-terminal) 0 (macro (self args env) | |
4 | (bind event (head args) | |
5 | (bind payload (head (tail args)) | |
6 | (if (equal? event (literal readln)) | |
7 | (list 0 (list (literal writeln) payload)) | |
8 | (list 0)))))) | |
9 | (reactor (line-terminal) 65 (macro (self args env) | |
10 | (bind event (head args) | |
11 | (bind payload (head (tail args)) | |
12 | (bind state (head (tail (tail args))) | |
13 | (if (equal? state 67) | |
14 | (list state (list (literal close) 0)) | |
15 | (if (equal? event (literal readln)) | |
16 | (list (inc state) (list (literal writeln) (list state))) | |
17 | (list state)))))))) | |
0 | (define inc (macro (self args env) | |
1 | (subtract (eval env (head args)) (subtract 0 1)))) | |
2 | (reactor (line-terminal) 65 | |
3 | (macro (self args env) | |
4 | (bind state (head (tail args)) | |
5 | (bind event (head args) | |
6 | (bind event-type (head event) | |
7 | (bind event-payload (head (tail event)) | |
8 | (if (equal? event-type (literal readln)) | |
9 | (if (equal? state 68) | |
10 | (list state (list (literal stop) 0)) | |
11 | (list (inc state) (list (literal writeln) event-payload))) | |
12 | (list state)))))))) | |
13 | (reactor (line-terminal) 65 | |
14 | (macro (self args env) | |
15 | (bind state (head (tail args)) | |
16 | (bind event (head args) | |
17 | (bind event-type (head event) | |
18 | (bind event-payload (head (tail event)) | |
19 | (if (equal? event-type (literal readln)) | |
20 | (list (inc state) (list (literal writeln) (list state))) | |
21 | (list state)))))))) |