The language in one page
Buraaq reads like Python you already know. It compiles to native code. There is one way to do each basic thing.
fn add(a: int, b: int) -> int {
a + b
}
fn main() {
name = "Asim"
mut score = 0
score = score + add(2, 3)
println("Hello, {name}")
}
No use. println is unique in the stdlib, so the project injects the import.
Files
.bq, UTF-8, 4 spaces inside{ }#line comment- Path under
src/is the module: modules
Bindings
name = "Asim" # immutable
mut score = 0 # reassignable
const MAX = 1024
Parameters have types. Locals are inferred.
Logic
Only bool in conditions. Use && and ||.
if age >= 18 && active {
println("ok")
}
Strings interpolate
"Hello, {name}" substitutes {name}. Do not put HTML or JSON inside a Buraaq "..." string. Keep those in files.
ok is a keyword.
Auto-import vs use
| Name | use required? |
|---|---|
Unique std.* function (println, page, run, hold) | No, in a project |
| A name you defined in this file | No |
A pub item in another of *your* modules | Yes: use tx.signed |
| A std name that is not unique | Yes, write use |
Generics
fn min[T](a: T, b: T) monomorphizes. Guest copies today: int (min, icmp), text (min__text), float (min__float), and a named struct at the call site (min__Pair, Pair_lt).
fn min[T](a: T, b: T) -> T {
if a.lt(b) { a } else { b }
}
fn main() {
println(min(3, 7))
println(min("b", "a"))
println(min(2.5, 1.25))
}
Trait bounds past those four copies are still growing. Write [1, 2] and { "k": v } instead of List[T] / Map[K,V] constructors.
Speed is the default
This is not a VM. buraaq build --release is LLVM. Hot loops should look like ordinary for / while. Gate B: integer_sum is 0.00× at n=1e8; worst published is fib_iter 1.02×. Method and table: performance.
Next we pick one program and keep extending it: a banking CLI.
