test.ox (2262B)
ns main
use io, std
pub rec Vehicle {
uint8 age
uint16 cc
str model
str name
str owner_name
float value() = age * cc
bool sold = false
Vehicle parent
}
inline pub int add (int a, b) => a + b
async int add (int a, b) => await sendoff(a, b)
const int jack = 7
const uint16 jill = 12
Vehicle build_vehicle (Vehicle v) inline pub {
v = { age: 12, cc: 1200, model: "Roaster" }
ret v
}
void print_vehicle(Vehicle v) {
print "Vehicle {{v.name}} is {{v.age}} yrs old with {{v.cc}} CC."
}
void main () {
Vehicle mazda = new { age: 12, cc: 1200, model: "Miata" }
print("mazda value is {{mazda.value}}")
print_vehicle(mazda)
print(add(5, 6)
for Vehicle v in cars {
print_vehicle <- v
}
cars -> each { v, i: print_vehicle v }
// shorthand argument in closures
[]Vehicle old_cars = cars.where(v: v.age > 10)
[]Vehicle big_cars = cars -> where { .cc > 2000 } -> map { .model }
[]Vehicle new_cars = cars
-> where { Vehicle v => v.age < 5 }
-> sorted { Vehicle a, b => a.model > b.model }
-> map { Vehicle v => v.model }
-> each { str model => print(model) }
[]Vehicle new_cars = cars
-> where { .age < 5 }
-> sorted { (Vehicle a, b) => a.age > b.age }
-> map { .model -> to_lower }
-> each { print }
http_server(8080, {sel: get_certif("certs/digitech.cert")})
http_server <- 8080, ssl: get_certif <- "certs/digitech.cert"
HttpServer server = (HttpServer)
-> init
-> serve <- port: 8080, ssl: get_certif <- paths -> where { .link = "private" }
-> background
HttpServer server = new {}
-> init()
-> serve(port: 8080, ssl: get_certif(paths.where { .link == "private" }))
-> background()
pub rec Cert { ... }
pub rec HttpServer {
void init() { ... }
void serve(int port, Cert ssl) { ... }
void background() { ... }
}
extend HttpServer {
void print { ... }
}
print <- "hello world"
print <- "hello world" -> capitalised // print("hello world".capitalised())
print <- capitalise <- "hello world" // print(capitalise("hello world"))
}