First, build and run the NG interpreter:
mkdir build && cd build
cmake .. && make
./ngi
print("Hello world!");
// Primitive types
val anInt = 1;
val aString = "string";
val aBool = true;
// Collections
val anArray = [1, 2, 3];
// Type declarations
type Person {
property name;
property age;
}
if (x > 0) {
print("Positive");
} else if (x < 0) {
print("Negative");
} else {
print("Zero");
}
fun square(x) {
return x * x;
}
fun factorial(n) {
if (n <= 1) return 1;
return n * factorial(n - 1);
}
File: math.ng
module math exports *;
fun add(a, b) {
return a + b;
}
fun sub(a, b) {
return a - b;
}
import "math" m;
val sum = m.add(2, 3);