2025-06-27 22:48:27 +00:00
|
|
|
fn receive (receiver) -> {
|
|
|
|
print! ("receiving in", self (), "with msgs", msgs())
|
|
|
|
if empty? (msgs ())
|
|
|
|
then {yield! (); receive (receiver)}
|
|
|
|
else do msgs () > first > receiver
|
2025-06-27 03:28:17 +00:00
|
|
|
}
|
2025-06-27 00:30:40 +00:00
|
|
|
|
2025-06-27 22:48:27 +00:00
|
|
|
fn foo? (val) -> receive (fn (msg) -> match report!("scrutinee is", msg) with {
|
|
|
|
(:report) -> {
|
|
|
|
print! ("LUDUS SAYS ==> value is {val}")
|
|
|
|
flush! ()
|
|
|
|
foo? (val)
|
|
|
|
}
|
|
|
|
(:set, x) -> {
|
|
|
|
print! ("LUDUS SAYS ==> foo! was {val}, now is {x}")
|
|
|
|
flush! ()
|
|
|
|
foo? (x)
|
|
|
|
}
|
|
|
|
(:get, pid) -> {
|
|
|
|
print! ("LUDUS SAYS ==> value is {val}")
|
|
|
|
send (pid, (:response, val))
|
|
|
|
flush! ()
|
|
|
|
foo? (val)
|
|
|
|
}
|
|
|
|
x -> print! ("LUDUS SAYS ==> no match, got {x}")
|
|
|
|
})
|
2025-06-27 00:30:40 +00:00
|
|
|
|
2025-06-27 22:48:27 +00:00
|
|
|
let foo = spawn! (fn () -> foo? (42))
|
|
|
|
print! (foo)
|
|
|
|
send (foo, (:set, 23))
|
|
|
|
yield! ()
|
|
|
|
send (foo, (:get, self ()))
|
|
|
|
yield! ()
|
|
|
|
fn id (x) -> x
|
|
|
|
receive(id)
|