git @ Cat's Eye Technologies Robin / 370dcc3
Deal with reactors that return abort values, more gracefully. Chris Pressey 4 years ago
3 changed file(s) with 34 addition(s) and 18 deletion(s). Raw diff Collapse all Expand all
919919 reference implementation will display them if `--show-events` is given)
920920 but this is not a strict requirement.
921921
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
939939
940940 Reactors can keep state.
941941
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)))))))
3131 (List (state':commands)) ->
3232 (reactor{ state=state' }, applyStop commands)
3333 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]])
3537
3638
3739 updateMany :: [Reactor] -> Expr -> ([Reactor], [Expr])