+// simply declare external functions\r
+func puts(str : char*) : void;\r
+\r
+// global context can contain functions,\r
+// structs, global variables and namespaces\r
+var global1 : int;\r
+var global2 : double = 123.45;\r
+\r
+func globalFunc() : void {\r
+ //puts("Hello\n");\r
+}\r
+\r
+// structs and functions can be declared generic\r
+// by providing a list of placeholder typenames\r
+struct S1<T1, T2> {\r
+ t1: T1;\r
+ t2: T1;\r
+\r
+ m1() : T2 {\r
+ return this->t1 + this->t2;\r
+ }\r
+}\r
+\r
+struct S2 {\r
+ s: char *;\r
+ abc(): S2 { }\r
+ xyz(): S2 { }\r
+}\r
+\r
+func generic1<A>(a1 : A, a2 : A) : A {\r
+ return a1 + a2;\r
+}\r
+\r
+// namespaces can contain everything that\r
+// the global context can\r
+\r
+namespace N1 {\r
+ var v1 : int;\r
+ func f1() : void {\r
+ puts("Hello\n");\r
+ }\r
+ struct S1 {\r
+ test : char *;\r
+ }\r
+ // nested namespaces\r
+ namespace N2 {\r
+ var v1 : int;\r
+ struct S1 {\r
+ i1 : int;\r
+ i2 : int;\r
+ i3 : int;\r
+\r
+ m1(i: int) : int {\r
+ // implicit 'this' parameter, pointer to containing struct\r
+ this->i3 = this->i1 * this->i2;\r
+\r
+ // lookup is done hierarchically\r
+ f1(v1); // this is basically N1::N2::f1(N1::N2::v1);\r
+ N1::f1(N1::v1); // the rest becomes exactly what they say\r
+ N2::f1(N2::v1);\r
+ N1::N2::f1();\r
+\r
+ return this->i1 + this->i2;\r
+ }\r
+ }\r
+\r
+ func f1() : void {\r
+ // these have the same type\r
+ var s1 : N1::N2::S1;\r
+ var s2 : S1;\r
+\r
+ s1.m1(123);\r
+ }\r
+ }\r
+}\r
+\r
+func main(argc : int, argv : char**) : int {\r
+ var s1 : N1::N2::S1;\r
+ var s2 : N1::N2::S1;\r
+ var s3 : N1::S1;\r
+ s1.i1 = 123;\r
+ s1.i2 = 456;\r
+ s1.m1(s2.m1(s3.m1(89)));\r
+\r
+ N1::N2::f1();\r
+\r
+ // one 'copy' is compiled for every unique instantiation\r
+ var s4 : S1<int, long>;\r
+ s4.t1 = 123; \r
+ s4.t2 = 456; \r
+ s4.m1();\r
+\r
+ generic1<int>(1, 2);\r
+ generic1<double>(3.4, 5.6);\r
+\r
+ var s: S2;\r
+ s.abc().xyz();\r
+\r
+ return 0;\r
+}
\ No newline at end of file