language

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

sillylinkedobject.ti (664B)


      1 class SillyLinkedObject(int id):
      2 {
      3 	string value = "pineapple";
      4 
      5 	var next as SillyLinkedObject;
      6 
      7 	if (id - 1) > 0:
      8 	{
      9 		next = new SillyLinkedObject(id - 1);
     10 	}
     11 
     12 	func get_id(int target_id) -> SillyLinkedObject:
     13 	{
     14 		var rv as SillyLinkedObject;
     15 
     16 		if id == target_id:
     17 		{
     18 			rv = ref;
     19 		}
     20 		else:
     21 		{
     22 			if id > 0:
     23 			{
     24 				rv = next.get_id(target_id);
     25 			}
     26 		}
     27 
     28 		return rv;
     29 	}
     30 
     31 }
     32 
     33 func do_test -> SillyLinkedObject:
     34 {
     35 	var rv = new SillyLinkedObject(20);
     36 
     37 	return rv;
     38 }
     39 
     40 SillyLinkedObject root = do_test();
     41 
     42 SillyLinkedObject number_3 = root.get_id(3);
     43 
     44 number_3.value = "porcuepine";
     45 print number_3.id;
     46 print number_3.value;
     47 
     48 print root.id;
     49 print root.value;