summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2015-12-21 21:39:28 -0800
committerOri Bernstein <ori@eigenstate.org>2015-12-21 21:39:28 -0800
commit00affd843ab9b371c3a18bfa79b4d82b261911a1 (patch)
tree478d76a63ae47e25c6767aa4f785918973f522bc /test
parent2e89856cee5ff88161295f3ea0d200f72eb4d31f (diff)
downloadmc-00affd843ab9b371c3a18bfa79b4d82b261911a1.tar.gz
Add custom iterators.
Diffstat (limited to 'test')
-rw-r--r--test/custiter.myr33
-rw-r--r--test/tests1
2 files changed, 34 insertions, 0 deletions
diff --git a/test/custiter.myr b/test/custiter.myr
new file mode 100644
index 0000000..53238cd
--- /dev/null
+++ b/test/custiter.myr
@@ -0,0 +1,33 @@
+use std
+
+type range = struct
+ lo : int
+ hi : int
+;;
+
+/* iterate up to 100 */
+impl iterable range -> int =
+ __iternext__ = {rng, output
+ if rng.lo > rng.hi
+ -> false
+ else
+ output# = rng.lo++
+ -> true
+ ;;
+ }
+
+ __iterfin__ = {it, val
+ }
+;;
+
+const main = {
+ var r : range
+ var x : int
+
+ r = [.lo=6, .hi=11]
+ for v in r
+ x = v
+ std.put("{}", x)
+ ;;
+ std.put("\n")
+}
diff --git a/test/tests b/test/tests
index eb38ffc..4753f91 100644
--- a/test/tests
+++ b/test/tests
@@ -66,6 +66,7 @@ B fncast P ok
B loop P 0123401236789
B subrangefor P 12
B patiter P 23512
+B custiter P 67891011
B condiftrue E 7
B condiffalse E 9
B condifrel E 7