Rakhyvel/Orng
Orng is a modern systems programming language designed for developers who want fine-grained control without sacrificing expressiveness
β οΈWARNING! Orng is still a work in progress! Expect exciting changes and improvements.
Orng is a versatile systems programming language I've been developing that gives developers control without sacrificing expressiveness. It is designed to be both lightweight and simple, making it a great choice for enthusiasts and professionals alike.
# Orng compiler requires Zig 0.13.0 at the moment
git clone --recursive https://github.com/Rakhyvel/Orng.git
# Set the Orng Standard Library path environment variable
# For Linux:
export ORNG_STD_PATH="/wherever/you/put/Orng/std"
# For Windows:
$env:ORNG_STD_PATH="/wherever/you/put/Orng/std"
# Build Orng
cd Orng
zig build orng
A fancy hello-world example:
fn main(sys: System) -> !() {
greet("Orng! π", sys.stdout) catch unreachable
}
fn greet(recipient: String, out: $T impl Writer) -> T::Error!() {
try out.>println("Hello, {s}", recipient)
}
Run it with:
orng run
Orng comes with a wide range of features that make it a powerful and flexible programming language, including:
In Orng, types are values. You can pass them to functions, return them, match on them, and construct them programmatically.
fn make_array_type(const n: Int, const T: Type) -> Type { [n]T }
fn main() {
let x: template(4, Char) = ('1', '2', '3', '4')
println("{c} squared is 9", x[3])
}
Pattern matching in Orng lets you elagantly deconstruct complex data structures with a single, readable expression. Forget verbose if-else
chains and nested conditionals - match on ADTs, extract values, and handle different cases with unprecedented clarity.
const Person = (name: String, age: Int, job: String)
fn classify_person(person: Person) -> String {
match person {
(name, age, "Teacher") if age > 50 => "Veteran Educator"
(name, _, "Doctor") => "Medical professional"
(_, age, _) if age < 18 => "Baby πΆ"
}
}
Algebraic Data Types (ADTs) allow you to define types that can be one of several variants with zero runtime overhead. Represent complex state machines, parse abstract syntax trees, or handle error conditons with a single, compact type definition.
const Shape = (
| circle: (radius: Float)
| rectangle: (width: Float, height: Float)
| triangle: (base: Float, height: Float))
fn calculate_area(shape: Shape) -> Float {
match shape {
.circle(r) => 3.14 * r * r
.rectangle(w, h) => w * h
.triangle(b, h) => 0.5 * b * h
}
}
Compile to C and parse C header files with ease. Orng bridges the gap between low-level system programming and high-level expressiveness.
Traits offer a flexible way to define behavior that can be attatched to any type. Instead of deep inheritance hierarchies, Orng lets you extend types with new capabilities through simple composable traits.
trait Counter {
fn increment(&mut self) -> Int
fn total(&self) -> Int
fn reset(&mut self) -> ()
}
impl Counter for (count: Int, max: Int) {
fn increment(&mut self) -> Int {
self.count = (self.count + 1) % self.max
self.count
}
fn total(&self) -> Int { self.count }
fn reset(&mut self) -> () { self.count = 0 }
}
fn main(sys: System) -> !() {
let mut counter = (0, 5)
try sys.stdout.>println("{d}", counter.>increment()) // Prints 1
try sys.stdout.>println("{d}", counter.>increment()) // Prints 2
}
Contributions of all kinds are welcome:
Check out CONTRIBUTING.md for more info!
Orng is open-source and released under the MIT License. See LICENSE
for details.