tobogganSe connecter

louise

The Louise language: compiler, runtime, std, tooling

Clone avec HTTPS, un jeton personnel en mot de passe, ou avec SSH, une clé ajoutée dans vos paramètres.

24 lignes · 851 octetsBrut · Historique
1/// Work another node starts here (`dist.spawn_on`): a `@remote` function
2/// is the only code a node runs on another's request.
3
4import std/list
5import std/os
6import std/process.{type Subject, type proc}
7import std/string
8
9/// A text to count the words of, and where to send the count.
10pub type Job { Job(text: String, reply: Subject<Counted>) }
11
12/// How many words, counted on which node.
13pub type Counted { Counted(words: Int, node: String) }
14
15/// Count `job`'s words and reply. Its argument came off the wire, checked
16/// against `Job`'s type; its reply subject is the asking node's.
17@remote
18pub fn count :: job: Job -> () / <proc, io>
19{
20 let words =
21 string.split job.text " " |> list.filter fn w { w != "" } |> list.length
22 let node = match os.env "LOUISE_NODE" { Some(n) -> n, None -> "?" }
23 process.send job.reply Counted(words, node)
24}