implemented method call
This commit is contained in:
parent
d3095d5980
commit
d269425943
8 changed files with 352 additions and 253 deletions
37
example/data/list.mc
Normal file
37
example/data/list.mc
Normal file
|
@ -0,0 +1,37 @@
|
|||
// Constructor.
|
||||
fn List() {
|
||||
let result = {
|
||||
data: [],
|
||||
push: (self, item) => {
|
||||
push(self.data, item);
|
||||
},
|
||||
pop: (self) => {
|
||||
return pop(self.data);
|
||||
},
|
||||
len: (self) => {
|
||||
return len(self.data);
|
||||
}
|
||||
};
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// Instantiation.
|
||||
let list = List();
|
||||
print("new list", list);
|
||||
|
||||
// Pushing 5 items in a loop.
|
||||
let index = 0;
|
||||
loop {
|
||||
if (index >= 5) break;
|
||||
list.push(index);
|
||||
index = index + 1;
|
||||
}
|
||||
|
||||
print("pushed list", list); // Misc accesses.
|
||||
print("length list", list.len()); // Misc accesses.
|
||||
print("poped item", list.pop()); // Misc accesses.
|
||||
print("poped list", list); // Misc accesses.
|
||||
|
||||
print("list.data", list.data);
|
||||
print("list[\"data\"]", list["data"]);
|
Loading…
Add table
Add a link
Reference in a new issue