summaryrefslogtreecommitdiff
path: root/Test/dafny0/Iterators.dfy
diff options
context:
space:
mode:
authorGravatar Rustan Leino <leino@microsoft.com>2012-09-26 00:09:04 -0700
committerGravatar Rustan Leino <leino@microsoft.com>2012-09-26 00:09:04 -0700
commit225930765d1f6c11dcf6c523ce0730457c07ec47 (patch)
tree5ea7ecbd4e5a972ea27c64dc5a6f1004647603fc /Test/dafny0/Iterators.dfy
parent3aac24b3f84b0c969e08a13aee01c75457c43851 (diff)
Dafny: compile iterators
Diffstat (limited to 'Test/dafny0/Iterators.dfy')
-rw-r--r--Test/dafny0/Iterators.dfy30
1 files changed, 30 insertions, 0 deletions
diff --git a/Test/dafny0/Iterators.dfy b/Test/dafny0/Iterators.dfy
new file mode 100644
index 00000000..76a30330
--- /dev/null
+++ b/Test/dafny0/Iterators.dfy
@@ -0,0 +1,30 @@
+iterator MyIter<T>(q: T) yields (x: T, y: T)
+{
+}
+
+iterator MyIntIter() yields (x: int, y: int)
+{
+ x, y := 0, 0;
+ yield;
+ yield 2, 3;
+ x, y := y, x;
+ yield;
+}
+
+method Main() {
+ var m := new MyIter.MyIter(12);
+ var a := m.x;
+ // assert !a; // error: type mismatch
+ if (a <= 13) {
+ print "-- ", m.x, " --\n";
+ }
+
+ var n := new MyIntIter.MyIntIter();
+ var patience := 10;
+ while (patience != 0) {
+ var more := n.MoveNext();
+ if (!more) { break; }
+ print n.x, ", ", n.y, "\n";
+ patience := patience - 1;
+ }
+}