This commit is contained in:
2026-01-13 22:52:55 +08:00
commit 211a837468
18 changed files with 2831 additions and 0 deletions

52
example.chun Normal file
View File

@@ -0,0 +1,52 @@
// Example Camellya script
// This demonstrates the Person class from the specification
class Person {
number age;
string name;
func sayHi() -> string {
print(name, "says: I'm", age, "years old");
return "Done";
}
func birthday() -> number {
age = age + 1;
print(name, "is now", age, "years old!");
return age;
}
}
// Create an instance
Person p;
p.age = 10;
p.name = "Peter";
// Call methods
p.sayHi();
p.birthday();
p.sayHi();
// Test lists (0-indexed)
print("\n=== List Demo ===");
list numbers = [1, 2, 3, 4, 5];
print("List:", numbers);
print("First element (index 0):", numbers[0]);
print("Third element (index 2):", numbers[2]);
// Test maps
print("\n=== Map Demo ===");
map config = {"host": "localhost", "port": "8080"};
print("Config:", config);
print("Host:", config["host"]);
// Functions
print("\n=== Function Demo ===");
func fibonacci(number n) -> number {
if (n <= 1) {
return n;
}
return fibonacci(n - 1) + fibonacci(n - 2);
}
print("Fibonacci(10) =", fibonacci(10));