-
Notifications
You must be signed in to change notification settings - Fork 3
/
idiom.hum
63 lines (56 loc) · 1.26 KB
/
idiom.hum
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
58
59
60
61
62
63
#
# Mycelia Actor Idioms
#
LET b_ignore = \_.[]
CREATE a_ignore WITH b_ignore
LET b_forward(cust) = \msg.[
SEND msg TO cust
]
CREATE a_forward WITH b_forward(a_ignore)
LET b_oneshot(cust) = \msg.[
SEND msg TO cust
BECOME b_ignore
]
CREATE a_oneshot WITH b_oneshot(a_ignore)
LET b_label(cust, label) = \msg.[ SEND (label, msg) TO cust ]
LET b_tag(cust) = \msg.[ SEND (SELF, msg) TO cust ]
LET b_fork(cust, head, tail) = \(h_req, t_req).[
CREATE k_head WITH b_tag(SELF)
CREATE k_tail WITH b_tag(SELF)
SEND (k_head, h_req) TO head
SEND (k_tail, t_req) TO tail
BECOME b_join(cust, k_head, k_tail)
]
LET b_join(cust, k_head, k_tail) = \msg.[
CASE msg OF
($k_head, first) : [
BECOME \($k_tail, rest).[
SEND (first, rest) TO cust
]
]
($k_tail, rest) : [
BECOME \($k_head, first).[
SEND (first, rest) TO cust
]
]
END
]
CREATE a_fork WITH \(cust, (head, h_req), (tail, t_req)).[
CREATE fork WITH b_fork(cust, head, tail)
SEND (h_req, t_req) TO fork
]
LET b_const(value) = \cust.[ SEND value TO cust ]
LET b_race(list) = \(cust, req).[
CREATE once WITH b_oneshot(cust)
send_to_all((once, req), list)
]
LET send_to_all(msg, list) = [
CASE list OF
() : []
(first, rest) : [
SEND msg TO first
send_to_all(msg, rest)
]
(last) : [ SEND msg TO last ]
END
]