/// Work another node starts here (`dist.spawn_on`): a `@remote` function /// is the only code a node runs on another's request. import std/list import std/os import std/process.{type Subject, type proc} import std/string /// A text to count the words of, and where to send the count. pub type Job { Job(text: String, reply: Subject) } /// How many words, counted on which node. pub type Counted { Counted(words: Int, node: String) } /// Count `job`'s words and reply. Its argument came off the wire, checked /// against `Job`'s type; its reply subject is the asking node's. @remote pub fn count :: job: Job -> () / { let words = string.split job.text " " |> list.filter fn w { w != "" } |> list.length let node = match os.env "LOUISE_NODE" { Some(n) -> n, None -> "?" } process.send job.reply Counted(words, node) }