Home / Highlights / FAQ / Examples / Quick Start / Roadmap / Download / About Us

NOTICE: We didn't get around to implementing structs and classes as an array. Previously it had been implemented as a template but templates bloated fast so we switched to generics. We almost reimplemented it with generics but we weren't happy with generic preformance so that got cut for now. A struct and class without initializers or constructor should work with a fixed length array but it hasn't been tested as much as the other features

struct ABC {
	int a = 5, b = 8, c //uninitialized variables default to 0
}
main() {
	ABC a
	assert(a.a == 5 && a.b == 8 && a.c == 0)
	assert(Is456(decl ABC{4, 5, 6})) //Must initialize all variables
	//TODO allow _ to mean default value
	assert(!Is456(a))
	main2()
}

Is456(ABC abc) bool { return abc.a == 4 && abc.b == 5 && abc.c == 6 }

////////////////

class RAIIClass
{
	int dummy
	constructor() { print("RAIIClass Constructing") }
	destructor()  { print("RAIIClass Destructing") }
}
class Test
{
	int+ a, b //+ means we want positive values that can fit into a signed int
	RAIIClass member //member constructor/destructor fully works
	constructor() { print("Constructing") }
	destructor()  { print("Destructing $a, $b") }

	//Property
	int Alpha get { return a } set
	{ 
		//'a' must be positive, we'll get an error if we don't ensure it
		if value >= 0
			a .= value
		else {
			a .= 0
		}
	}
	int Beta  get { return b*b } //no setter

	//We're not an array but lets implement this
	operator[](s64 index) int const {
		//TODO switch
		if index == 0
			return a
		else if index == 1
			return b
		else
			return 0
	}
	//This is the setter
	operator[](int index, int+ value) int {

		if index == 0
			return a .= value + 10
		else if index == 1
			return b .= value + 20
		else
			return 0
	}
}

AlphaBeta(Test t) int { return t.Alpha + t.Beta }

main2()
{
	Test t
	t.Alpha .=  1; assert(t.Alpha == 1)
	t.Alpha .= -5; assert(t.Alpha == 0)
	assert(t.Beta == 0)
	t[0] .= 1 //indexer added 10 on set
	t[1] .= 2 //indexer added 20 on set
	t[2] .= 5
	assert(t[0] == 11)
	assert(t[1] == 22)
	assert(t[3] == 0)
	assert(t.Alpha == 11)
	assert(t.Beta == 484)
	assert(AlphaBeta(t) == 495)
	//Because of extend (below) we can do this
	assert(t.AlphaBeta() == 495)
}

extend AlphaBeta