You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// TODO: defaults
// TODO: tagging
// TODO: setters
structure greeter {
sint num_greeted
string greeting : getter (greeter self) => {
return "Hello! You're the " + string(self.num_greeted) + " person to be greeted"
}
}
Unions
Type Inspection
tags
struct.for_each_member
Operators
Functions
fn add_two_s64(sint a, sint b) -> sint {
return a + b
}
// returns a function that returns a string
fn create_greeter_fn(string name) -> fn() -> string {
// lambda synax
return () => "Hello " + name + "!"
}
// adds any type with itself that implements the + trait
fn add_two<T>(T a, T b) -> T {
return a + b
}
Variable Definitions
let a sint
let b sint = 100
const c sint = 100 // MUST be defined at compile time
Variable Tagging
Traits
Imports
// imports must be at the start of the file, though comments are allowed before imports
import module_a
import module_b.module_ba
import module_c as mod_c
from module_d import print_d, is_d
import module_e
import module_item
fn example_a() -> module_item:item {
module_a:print_a()
module_b:module_b:print_ba()
mod_c:print_c()
return module_item:make_item()
}
fn example_b() {
use module_a // applies to the current block scope
print_a()
use module_e {
print_e()
}
}
// types and functions are exported with pub
pub fn my_fn() {}
pub struct my_struct {}
pub union {}
Basic Control Structures
if
if condition {
call_function()
}
// parens are required if you don't use curly braces
if (condition) call_function()
if (condition1) {
func1()
} elif (condition2) {
func2()
} else {
func3()
}
While & Do While
let counter uint
while counter != 10 {
do_something()
counter++
}
// parens are required if you don't use curly braces
while (get_status() == status.failed) retry()