Quoin

/kɔɪn/ · pronounced “coin”

A small language built from blocks — and the messages they pass.

Quoin is a Smalltalk-inspired programming language running on a virtual machine written in Rust. First-class blocks, message passing all the way down, and multi-method dispatch at the core.

A taste of Quoin

"* Classes with <- , methods with -> , and blocks are { }
Point <- { |@x @y|
    dist -> { ((@x * @x) + (@y * @y)).sqrt }
}

p = Point.new:{ x = 3; y = 4 }
p.dist                               "* 5

"* No control-flow keywords — if: is just a message to a boolean
(p.dist > 4).if:{ 'far'.print } else:{ 'near'.print }

"* Blocks are values — hand one to a collection
#(1 2 3 4 5).collect:{ |n| n * n }    "* #(1 4 9 16 25)

Fibers — coroutines, built in

"* A Fiber is a coroutine — it yields a value, then pauses
"* with all its state intact until you resume it.
fib = Fiber.new:{
    a = 0; b = 1
    { true }.whileDo:{ Fiber.yield:a; t = a + b; a = b; b = t }
}

fib.resume      "* 0
fib.resume      "* 1
fib.resume      "* 1
fib.resume      "* 2

"* Wrap that same yielding block in a Generator and you get
"* a lazy, infinite sequence you can take from:
fibs = Generator.from:{ a = 0; b = 1; { true }.whileDo:{ ^> a; t = a + b; a = b; b = t } }
fibs.take:10    "* #(0 1 1 2 3 5 8 13 21 34)
In active development