1 // simply declare external functions
\r
2 func puts(str : char*) : void;
\r
4 // global context can contain functions,
\r
5 // structs, global variables and namespaces
\r
7 var global2 : double = 123.45;
\r
9 func globalFunc() : void {
\r
13 // structs and functions can be declared generic
\r
14 // by providing a list of placeholder typenames
\r
20 return this->t1 + this->t2;
\r
24 func generic1<A>(a1 : A, a2 : A) : A {
\r
28 // namespaces can contain everything that
\r
29 // the global context can
\r
39 // nested namespaces
\r
48 // implicit 'this' parameter, pointer to containing struct
\r
49 this->i3 = this->i1 * this->i2;
\r
51 // lookup is done hierarchically
\r
52 f1(v1); // this is basically N1::N2::f1(N1::N2::v1);
\r
53 N1::f1(N1::v1); // the rest becomes exactly what they say
\r
57 return this->i1 + this->i2;
\r
70 // these have the same type
\r
71 var s1 : N1::N2::S1;
\r
81 get(index: int): T {
\r
82 return this->array[index];
\r
86 func main(argc : int, argv : char**) : int {
\r
87 var s1 : N1::N2::S1;
\r
88 var s2 : N1::N2::S1;
\r
92 s1.m1(s2.m1(s3.m1(89)));
\r
96 // one 'copy' is compiled for every unique instantiation
\r
97 var s4 : S1<int, long>;
\r
102 generic1<int>(1, 2);
\r
103 generic1<double>(3.4, 5.6);
\r
111 var i1: int = generic1<int>(1, 2);
\r