Skip to content
Bill Hails edited this page Jun 2, 2018 · 2 revisions

Spawn is a simple "green" (language rather than operating-system level) thread creator. It returns true to one thread and false to the other so that they can behave differently. There's honestly no real application for this feature yet, it's just a demonstration that it is possible.

Example from the tests:

{
    fn factorial {
        (label, 0) {
            print(label);
            1
        }
        (label, n) {
            print(label);
            n * factorial(label, n - 1)
        }
    }
    if (spawn) {
        factorial("a", 5)
    } else {
        factorial("b", 6);
    }
}

prints:

a
b
a
b
a
b
a
b
a
b
a
b
b
120
720

To complement spawn there is the keyword exit that terminates the current thread.

Up: Home

Next: Strong, Implicit Type Checking

Clone this wiki locally