Support var
This commit is contained in:
12
example.chun
12
example.chun
@@ -2,8 +2,8 @@
|
||||
// This demonstrates the Person class from the specification
|
||||
|
||||
class Person {
|
||||
number age;
|
||||
string name;
|
||||
var age : number;
|
||||
var name : string;
|
||||
|
||||
func sayHi() -> string {
|
||||
print(name, "says: I'm", age, "years old");
|
||||
@@ -18,7 +18,7 @@ class Person {
|
||||
}
|
||||
|
||||
// Create an instance
|
||||
Person p;
|
||||
var p : Person;
|
||||
p.age = 10;
|
||||
p.name = "Peter";
|
||||
|
||||
@@ -29,12 +29,12 @@ p.sayHi();
|
||||
|
||||
// Test lists (0-indexed)
|
||||
print("\n=== List Demo ===");
|
||||
list numbers = [1, 2, 3, 4, 5];
|
||||
var numbers = [1, 2, 3, 4, 5];
|
||||
print("List:", numbers);
|
||||
print("First element (index 0):", numbers[0]);
|
||||
print("测试 element (index 2):", numbers[2]);
|
||||
|
||||
for(number i = 0; i < len(numbers); i = i + 1) {
|
||||
for(var i = 0; i < len(numbers); i = i + 1) {
|
||||
print("List element", numbers[i]);
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ while(true) {
|
||||
}
|
||||
// Test maps
|
||||
print("\n=== Map Demo ===");
|
||||
map config = {"host": "localhost", "port": "8080"};
|
||||
var config = {"host": "localhost", "port": "8080"};
|
||||
print("Config:", config);
|
||||
print("Host:", config["host"]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user