The Scarlet language
A typed language built around cheap, isolated processes.
Scarlet is not finished. The syntax and the standard library still change between releases, so there is no manual yet, only the ideas we are building it on.
Principles
- Values never change.
- Almost everything is an expression, so there is no
return. - Failure is a value, not an exception.
- You write types on functions and the compiler infers the rest.
- Concurrency comes from processes that share no memory.
A small program
This restocks anything on the shelf that has run out, then prints the shelf.
import scarlet/array
type Item {
name String
count Int
}
fn restock(item Item) Item {
match item.count {
0 -> Item(..item, count: 12)
_ -> item
}
}
pub fn main() {
shelf = [Item(name: 'tea', count: 4), Item(name: 'jam', count: 0)]
println(array.map(shelf, restock))
}
Install Scarlet, save the program as shelf.scrl and run it:
curl -fsSL scarlet.industries/install.sh | bash
scarlet run shelf.scrl
A bigger program puts a web server in front of a stock room.