A minimal, data-oriented functional programming language.
The Build workflow validates optimized release builds for macOS aarch64, Linux
amd64, and Windows amd64. Pushing a tag whose name starts with v publishes
those three SDK archives and their SHA256SUMS file to a GitHub Release
automatically.
// this is a comment
// use modules
use math
use std
// define a variable
leta=1 // default int literal type is i32; default float literal type is f32
letpi:f64=3.141592653lethello:str="hello world" // string literal
// define compile-time literal constants (global or local)
lit answer =6*7
lit precise: f64= answer asf64
// operators (see doc/operators.md for the full set)
letready=trueletblocked= !ready // unary logical not
letgo= ready && !(a ==0) // negate a compound expression
letdelta=-(a +1) // arithmetic negation of a group
letlow= a &~1 // bitwise not: clear the low bit
// define a function
fn add(a: f64, b: f64): f64{return a + b
}
// define a struct
struct Point {
x:f32,y: f32
}
// define a nominal enum; the underlying integer type defaults to i32
enumos_platform:u8{
unknown =0,
macos,}letplatform= os_platform.macos
letraw:u8= platform
letrestored= raw asos_platform
// operator override
fn ops(+)(lhs: Point, rhs: Point): Point {returnPoint(lhs.x + rhs.x, lhs.y + rhs.y)}
// to string fn
fn to_str(p: Point): str {return `{p.x}, {p.y}` // str formatter
}
// same-name fns: later defs are stored as name_FirstArgType
fn length(v: float3) f32{returnsqrt((v.x * v.x + v.y * v.y + v.z * v.z)asf64)asf32}fn length(v: float2) f32{returnsqrt((v.x * v.x + v.y * v.y)asf64)asf32}letpoint_a=Point(0,0)letpoint_b=Point(1,1)print(a + b) // use override add fn, expect result [1, 1]
// typealias
type number = f32
// union type: a value may be any one of the member types
type num = i32 | f64
letsome_num:num=1 // holds an i32
letother_num:num=3.14 // holds an f64
letn= some_num asi32 // narrow to a member with `as`
// block[closure]
// define a block or fn type
type op_fn =(i32, i32)-> i32
// define a block
letadd_op:op_fn={ a, b inreturn a + b
}fn sub(a: i32, b: i32): i32{return a - b
}
fn do_op(a: i32, b: i32, op: op_fn): i32{returnop(a, b)}fn main(){letret_add=do_op(1,2, add_op)letret_sub=do_op(2,1, sub)
print(`1 +2={ret_add}`)
print(`2 -1={ret_sub}`)
}
// define a asynchronous function
async fn download(url: str, on_data:(data: Data) to void): Data {letd=awaitdo_download(url)on_data(d)return d
}- Minimal syntax and keywords for ease of learning and use.
- Supports both interpretation and compilation.
- Utilizes an explicit type system, avoiding generic types.
- Follows a data-oriented programming approach.