Clarity
Contexts, aggregates, commands and events outline what your program is about, and a command's contract holds the business rules themselves.
Croft is a domain-driven programming language. It compiles to C89 with no runtime of its own, so your program runs wherever a C compiler does, from modern desktops to the ZX Spectrum and Atari ST.
$ git clone https://github.com/croftlang/lang croft && cd croft
$ cargo install --path crates/croft_cli
context Greeter {
publish { greet }
fn greet(): String where Length(0, 11) = {
"Hello, World"
}
}
domain Application {
contexts {
Greeter
}
use { greet } from Greeter
calls Console
} = {
let output = greet()
console.print(output) // Hello, World
}
Contexts, aggregates, commands and events outline what your program is about, and a command's contract holds the business rules themselves.
Constraints such as where Length(0, 32) and command contracts are checked by the compiler, so broken rules show up before runtime. Every type has a known size.
Croft compiles to C89. Ports and adapters keep the program the same on every machine, and croft.toml says what connects to them.
A value, field or function can carry a constraint. The compiler checks it, and debug builds stop when one is broken.
Bounds decide sizes too: Length(1, 8) keeps a name in eight characters of its own, not the size of every string.
context Clinic {
// Kept in eight characters of its own.
value Patient {
name: String where Length(1, 8)
}
value Dose {
amount: Int where Range(1, 50)
}
constraint Even(number: Int) = number % 2 == 0
fn half(number: Int): Int where Even = number / 2
}
The croft command checks, compiles and runs a project, and tells you how much memory each type and function takes on a target. croft lsp runs the language server for VS Code and Zed.
# check the program
$ croft check .
# check and compile to C
$ croft compile . --target desktop
# check, compile and run
$ croft run . --target desktop
# the memory each type and function takes
$ croft size . --target spectrum_48k