Skip to content
This repository has been archived by the owner on Jul 2, 2022. It is now read-only.

Latest commit

 

History

History
89 lines (72 loc) · 1.07 KB

Samples.md

File metadata and controls

89 lines (72 loc) · 1.07 KB

Code Examples

  1. Hello world
println( 'Hello world' );
  1. Variables
var = 2 + 4 * 6 / 8;
println( var );
  1. Arrays/Lists
var = [ 1, 2, 3, 4 ];
println( var[ 1 ] );
  1. Maps/Dictionaries
var = { 'str', 'test' };
var[ 'str' ] = 'test2';
println( var[ 'str' ] );
  1. Functions
fn hello( to ) {
	println( 'Hello ', to );
}

hello( 'world' );
  1. Conditionals
if 1 == 1 {
	print( 'One' );
} else {
	print( '1 ain\'t 1' );
}
  1. Loops (For)
num = int( scan( 'Enter factorial of: ' ) );
fact = 1;

for x = num; x >= 2; --x {
	fact *= x;
}

println( 'Factorial of ', num, ': ', fact );
  1. Loops (Foreach)
import std.vec;

a = [ 1, 2, 3 ];
for x in a.iter() {
	println( x );
}
  1. 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 ) );
  1. Structure Member functions
# first argument is implicitly the calling variable itself: used as 'self'
mfn< str > print() {
	println( self );
}

str = 'string';
str.print();