-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathinboxgen.rho
45 lines (45 loc) · 1.16 KB
/
inboxgen.rho
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
new stdout(`rho:io:stdout`), Inbox in {
contract Inbox(capabilities) = {
new read, write, peek, box in {
capabilities!(*read, *write, *peek) |
box!(Nil) |
contract read(pattern,ret) = {
stdout!(["pattern",*pattern]) |
for (items <- box) {
match (*items) {
{ {item} /\ {=*pattern} | rest} => {
stdout!(item) |
ret!(item) |
box!(rest)
}
_ => {box!(*items) | ret!(Nil)}
}
}
} |
contract write(message,ret) = {
for (items <- box) {
stdout!([*message, *items]) |
box!(*items | *message)|
ret!(Nil)
}
}
}
} |
new capabilities, ack, message in {
Inbox!(*capabilities) |
for (receive, send, peek <- capabilities) {
stdout!("received capabilities") |
send!(["chat","hello world"], *ack) |
send!(["chat","jimscarver" ++ ": Watson come quickly!"], *ack) |
for ( _ <- ack; _ <- ack) {
receive!(@["chat", ...]|, *message) |
for ( text <- message ) {
stdout!(*text)
} |
receive!({["chat", ...]}, *message) |
for ( text <- message ) {
stdout!(*text)
}
}
}
}}