aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2019-11-02 16:36:46 +0000
committergingerBill <bill@gingerbill.org>2019-11-02 16:36:46 +0000
commite3d3a81617dd78a9b193bbc07f2a29315774ff57 (patch)
treed285fd38b6daae5ac62a8adb10269d31b8f97135 /examples
parentdbdbbcd60f1273e246d11696476ac4772f91c258 (diff)
multivalued procedure calls allows in `for in` to allow a pseudo-iterator; `@thread_local` for variables in procedure
Diffstat (limited to 'examples')
-rw-r--r--examples/demo/demo.odin39
1 files changed, 39 insertions, 0 deletions
diff --git a/examples/demo/demo.odin b/examples/demo/demo.odin
index 4d14973f6..e91e3a924 100644
--- a/examples/demo/demo.odin
+++ b/examples/demo/demo.odin
@@ -1233,6 +1233,44 @@ ranged_fields_for_array_compound_literals :: proc() {
}
}
+range_statements_with_multiple_return_values :: proc() {
+ // IMPORTANT NOTE(bill, 2019-11-02): This feature is subject to be changed/removed
+ fmt.println("\n#range statements with multiple return values");
+ My_Iterator :: struct {
+ index: int,
+ data: []i32,
+ };
+ make_my_iterator :: proc(data: []i32) -> My_Iterator {
+ return My_Iterator{data = data};
+ }
+ my_iterator :: proc(it: ^My_Iterator) -> (val: i32, idx: int, cond: bool) {
+ if cond = it.index < len(it.data); cond {
+ val = it.data[it.index];
+ idx = it.index;
+ it.index += 1;
+ }
+ return;
+ }
+
+ data := make([]i32, 6);
+ for _, i in data {
+ data[i] = i32(i*i);
+ }
+
+ {
+ it := make_my_iterator(data);
+ for val in my_iterator(&it) {
+ fmt.println(val);
+ }
+ }
+ {
+ it := make_my_iterator(data);
+ for val, idx in my_iterator(&it) {
+ fmt.println(val, idx);
+ }
+ }
+}
+
main :: proc() {
when true {
extra_general_stuff();
@@ -1256,6 +1294,7 @@ main :: proc() {
inline_for_statement();
where_clauses();
ranged_fields_for_array_compound_literals();
+ range_statements_with_multiple_return_values();
}
}