53 lines
1.1 KiB
Plaintext
53 lines
1.1 KiB
Plaintext
// 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));
|