diff options
Diffstat (limited to 'examples/learn/19-growable.zc')
| -rw-r--r-- | examples/learn/19-growable.zc | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/examples/learn/19-growable.zc b/examples/learn/19-growable.zc index e5ed8de..39a484c 100644 --- a/examples/learn/19-growable.zc +++ b/examples/learn/19-growable.zc @@ -1,13 +1,18 @@ +namespace; +include rt; struct cnt { int n; static int make() { return 3; } int get() { return this.n; } }; fn main() { - []int xs = new([]int); - push(xs, 4); push(xs, 5); - put_n(len(xs)); put_c(10); - put_n(pop(xs)); put_c(10); - put_n(cnt.make()); put_c(10); - return 0; + int[?] xs = rt.new(int[?]); + xs.push(4); xs.push(5); + rt.put_n(xs.len()); rt.put_c(32); rt.put_n(xs.cap()); rt.put_c(10); + rt.put_n(xs.pop()); rt.put_c(10); + xs.resize(4); + rt.put_n(xs.len()); rt.put_c(10); + int[3] fixed = {1, 2, 3}; + rt.put_n(fixed.len()); rt.put_c(32); rt.put_n(fixed.cap()); rt.put_c(10); + rt.put_n(cnt.make()); rt.put_c(10); } |
