Deal with reactors that return abort values, more gracefully.
Chris Pressey
4 years ago
919 | 919 |
reference implementation will display them if `--show-events` is given)
|
920 | 920 |
but this is not a strict requirement.
|
921 | 921 |
|
922 | |
/| (reactor (line-terminal) 0
|
923 | |
/| (macro (args env)
|
924 | |
/| (bind event (head args)
|
925 | |
/| (bind event-type (head event)
|
926 | |
/| (bind event-payload (head (tail event))
|
927 | |
/| (if (equal? event-type (literal readln))
|
928 | |
/| (if (equal? (head event-payload) 65)
|
929 | |
/| (abort 999999)
|
930 | |
/| (list 0 (list (literal writeln) event-payload)))
|
931 | |
/| (list 0)))))))
|
932 | |
/+ Cat
|
933 | |
/+ Dog
|
934 | |
/+ Alligator
|
935 | |
/+ Bear
|
936 | |
/= Cat
|
937 | |
/= Dog
|
938 | |
/= Bear
|
|
922 |
| (reactor (line-terminal) 0
|
|
923 |
| (macro (args env)
|
|
924 |
| (bind event (head args)
|
|
925 |
| (bind event-type (head event)
|
|
926 |
| (bind event-payload (head (tail event))
|
|
927 |
| (if (equal? event-type (literal readln))
|
|
928 |
| (if (equal? (head event-payload) 65)
|
|
929 |
| (abort 999999)
|
|
930 |
| (list 0 (list (literal writeln) event-payload)))
|
|
931 |
| (list 0)))))))
|
|
932 |
+ Cat
|
|
933 |
+ Dog
|
|
934 |
+ Alligator
|
|
935 |
+ Bear
|
|
936 |
= Cat
|
|
937 |
= Dog
|
|
938 |
= Bear
|
939 | 939 |
|
940 | 940 |
Reactors can keep state.
|
941 | 941 |
|
|
0 |
;''Demonstrates what happens when a reactor receives an abort value
|
|
1 |
from its transducer. Running with --show-events will show the
|
|
2 |
abort message, but it will not be sent back to the reactor.''
|
|
3 |
|
|
4 |
(reactor (line-terminal) 0
|
|
5 |
(macro (args env)
|
|
6 |
(bind event (head args)
|
|
7 |
(bind event-type (head event)
|
|
8 |
(bind event-payload (head (tail event))
|
|
9 |
(if (equal? event-type (literal readln))
|
|
10 |
(if (equal? (head event-payload) 65)
|
|
11 |
(abort 999999)
|
|
12 |
(list 0 (list (literal writeln) event-payload)))
|
|
13 |
(list 0)))))))
|
31 | 31 |
(List (state':commands)) ->
|
32 | 32 |
(reactor{ state=state' }, applyStop commands)
|
33 | 33 |
expr ->
|
34 | |
(reactor, [List [(Symbol "malformed-response"), expr]])
|
|
34 |
-- make sure this event is ill-formed so that no reactors react to it
|
|
35 |
-- TODO handle this in a more elegant way
|
|
36 |
(reactor, [List [(Symbol "malformed-response"), (Symbol "malformed-response"), expr]])
|
35 | 37 |
|
36 | 38 |
|
37 | 39 |
updateMany :: [Reactor] -> Expr -> ([Reactor], [Expr])
|