
Small enough to know by heart. Safe and fast by construction.
SG is a small systems language that makes fast software safe by construction. One owner for every value, borrows checked when the program compiles, no garbage collector. It compiles through C and runs on Linux, macOS and Windows. It is before its preview.
Install Take the tour Look a word up
Small
Types before names, braces, no macros. A call says what it may do to your variable: read to
look, ref to change.
Fast
Compiled through C with no runtime to carry. SG is held to safe Rust doing the same work, and measured against C.
Safe
A use after free, a dangling pointer and a forgotten error are compile errors, each with the fix when it is known.
Get it
git clone https://github.com/sg-language/sg-lang
cd sg-lang/interpreter
cargo build --release # makes target/release/sg
sg hello.sg # runs a program
man sg-read # the page of a word
Point at a coloured word to see what it is; click it for its page.
int largest(read int[] values) {
var best = values[0]
for value in values {
if value > best {
best = value
}
}
return best
}
void scale(ref int[] values, int by) {
for i in 0..values.length() {
values[i] *= by
}
}
void main() {
var samples = int[4] { 3, 9, 4, 1 }
print(largest(read samples))
scale(ref samples, 2)
print(samples)
}
9
[6, 18, 8, 2]
A mistake is a compile error
A function lent the array with read may look at it and nothing more. Writing to
it does not compile, and the message says what to write instead.
int largest(read int[] values) {
values[0] = 0
return values[0]
}
void main() {
var samples = int[4] { 3, 9, 4, 1 }
print(largest(read samples))
}
error: this item is reached through a `read` borrow and cannot be written
--> main.sg:2:5
2 | values[0] = 0
| ^^^^^^^^^
hint: take the value as `ref` instead of `read`

