language

some fools attempt at an interpreted language
Log | Files | Refs | README

class.ti (575B)


      1 class Counter:
      2 {
      3 	int data = 0;
      4 
      5 	func count -> int:
      6 	{
      7 		data = data + 1;
      8 
      9 		return data;
     10 	}
     11 
     12 	func reset -> void:
     13 	{
     14 		data = 0;
     15 	}
     16 }
     17 
     18 class ObjectFibb(Counter acc):
     19 {
     20 	int a = 0;
     21 	int b = 1;
     22 
     23 	func next -> void:
     24 	{
     25 		b = a + b;
     26 		a = a + b;
     27 	}
     28 	
     29 	func display -> void:
     30 	{
     31 		print b;
     32 		print a;
     33 	}
     34 
     35 	func run (int count) -> void:
     36 	{
     37 		acc.reset();
     38 		while acc.count() < count:
     39 		{
     40 			next();
     41 			display();
     42 		}
     43 	}
     44 }
     45 
     46 Counter thing = new Counter();
     47 
     48 ObjectFibb test = new ObjectFibb(thing);
     49 
     50 test.run(15);
     51 print "ALL DONE!";
     52 print test.a;
     53 print test.b;
     54 print test.acc.data;
     55