After turning in the C/C++ monster (cleanest C code I reckon it is possible to write, thus the total lack of memory-mapped I/O and other optimizations), I turned my attention to picking a better implementation language.
- Good support for threading
- If possible, support for distributed computing
As it turns out, JoCaml fits the bill perfectly. It’s an extension of Ocaml, so it combines a rich library with a familiar syntax (not to me, but having used both Scheme and Haskell, how different can it be) — and a very nice process calculus!
Example: this is a concurrent stack that blocks if there is no input available
let new_stack () =
def state (s) & push (v) = state (v::s) & reply to push
or state (x::s) & pop () = state s & reply x to pop in
This defines a private state channel, and then export the pop and push synchronous channels (that to the user behave just like ordinary functions)
and this is how you use it:
let pop, push = new_stack ();;
Note that the echo channel will block, since pop can’t return a value until the stack contains something! This value is then pushed into the stack and ‘1’ printed.