- Hello world
println( 'Hello world' );
- Variables
var = 2 + 4 * 6 / 8;
println( var );
- Arrays/Lists
var = [ 1, 2, 3, 4 ];
println( var[ 1 ] );
- Maps/Dictionaries
var = { 'str', 'test' };
var[ 'str' ] = 'test2';
println( var[ 'str' ] );
- Functions
fn hello( to ) {
println( 'Hello ', to );
}
hello( 'world' );
- Conditionals
if 1 == 1 {
print( 'One' );
} else {
print( '1 ain\'t 1' );
}
- Loops (For)
num = int( scan( 'Enter factorial of: ' ) );
fact = 1;
for x = num; x >= 2; --x {
fact *= x;
}
println( 'Factorial of ', num, ': ', fact );
- Loops (Foreach)
import std.vec;
a = [ 1, 2, 3 ];
for x in a.iter() {
println( x );
}
- Structures & Objects
struct C {
a = 10;
b = 20;
}
fn mult_by( c, x ) { return c.a * c.b * x; }
c = C{};
print( mult_by( c, 5 ) );
- Structure Member functions
# first argument is implicitly the calling variable itself: used as 'self'
mfn< str > print() {
println( self );
}
str = 'string';
str.print();