From 91c4d57eb84d5d15e011902a1da1b70131e5a222 Mon Sep 17 00:00:00 2001 From: leino Date: Fri, 12 Dec 2014 20:46:48 -0800 Subject: Language change: All functions and methods declared lexically outside any class are now automatically static, and fields are no longer allowed to be declared there. Stated differently, all heap state must now be declared inside an explicitly declared class, and functions and methods declared outside any class can be viewed as belonging to the module. The motivating benefit of this change is to no longer need the 'static' keyword when declaring a module of functions and methods. --- Test/dafny1/Celebrity.dfy | 4 ++-- Test/dafny1/Substitution.dfy | 16 ++++++++-------- Test/dafny1/TreeDatatype.dfy | 12 ++++++------ 3 files changed, 16 insertions(+), 16 deletions(-) (limited to 'Test/dafny1') diff --git a/Test/dafny1/Celebrity.dfy b/Test/dafny1/Celebrity.dfy index 360c5aba..fb7a5fab 100644 --- a/Test/dafny1/Celebrity.dfy +++ b/Test/dafny1/Celebrity.dfy @@ -3,10 +3,10 @@ // Celebrity example, inspired by the Rodin tutorial -static function method Knows(a: X, b: X): bool +function method Knows(a: X, b: X): bool requires a != b; // forbid asking about the reflexive case -static function IsCelebrity(c: Y, people: set): bool +function IsCelebrity(c: Y, people: set): bool { c in people && (forall p :: p in people && p != c ==> Knows(p, c) && !Knows(c, p)) diff --git a/Test/dafny1/Substitution.dfy b/Test/dafny1/Substitution.dfy index 10b70e09..174e71c8 100644 --- a/Test/dafny1/Substitution.dfy +++ b/Test/dafny1/Substitution.dfy @@ -8,7 +8,7 @@ datatype Expr = Var(int) | Nary(int, List); -static function Subst(e: Expr, v: int, val: int): Expr +function Subst(e: Expr, v: int, val: int): Expr { match e case Const(c) => e @@ -16,14 +16,14 @@ static function Subst(e: Expr, v: int, val: int): Expr case Nary(op, args) => Expr.Nary(op, SubstList(args, v, val)) } -static function SubstList(l: List, v: int, val: int): List +function SubstList(l: List, v: int, val: int): List { match l case Nil => l case Cons(e, tail) => Cons(Subst(e, v, val), SubstList(tail, v, val)) } -static ghost method Theorem(e: Expr, v: int, val: int) +lemma Theorem(e: Expr, v: int, val: int) ensures Subst(Subst(e, v, val), v, val) == Subst(e, v, val); { match e { @@ -34,7 +34,7 @@ static ghost method Theorem(e: Expr, v: int, val: int) } } -static ghost method Lemma(l: List, v: int, val: int) +lemma Lemma(l: List, v: int, val: int) ensures SubstList(SubstList(l, v, val), v, val) == SubstList(l, v, val); { match l { @@ -52,7 +52,7 @@ datatype Expression = Var(int) | Nary(int, seq); -static function Substitute(e: Expression, v: int, val: int): Expression +function Substitute(e: Expression, v: int, val: int): Expression decreases e; { match e @@ -61,7 +61,7 @@ static function Substitute(e: Expression, v: int, val: int): Expression case Nary(op, args) => Expression.Nary(op, SubstSeq(e, args, v, val)) } -static function SubstSeq(/*ghost*/ parent: Expression, +function SubstSeq(/*ghost*/ parent: Expression, q: seq, v: int, val: int): seq requires (forall a :: a in q ==> a < parent); decreases parent, q; @@ -70,7 +70,7 @@ static function SubstSeq(/*ghost*/ parent: Expression, SubstSeq(parent, q[..|q|-1], v, val) + [Substitute(q[|q|-1], v, val)] } -static ghost method TheoremSeq(e: Expression, v: int, val: int) +lemma TheoremSeq(e: Expression, v: int, val: int) ensures Substitute(Substitute(e, v, val), v, val) == Substitute(e, v, val); { match e { @@ -97,7 +97,7 @@ static ghost method TheoremSeq(e: Expression, v: int, val: int) } } -static ghost method LemmaSeq(parent: Expression, q: seq, v: int, val: int) +lemma LemmaSeq(parent: Expression, q: seq, v: int, val: int) requires (forall a :: a in q ==> a < parent); ensures |SubstSeq(parent, q, v, val)| == |q|; ensures (forall k :: 0 <= k && k < |q| ==> diff --git a/Test/dafny1/TreeDatatype.dfy b/Test/dafny1/TreeDatatype.dfy index 763cef1b..beb1597e 100644 --- a/Test/dafny1/TreeDatatype.dfy +++ b/Test/dafny1/TreeDatatype.dfy @@ -7,13 +7,13 @@ datatype List = Nil | Cons(T, List); datatype Tree = Node(int, List); -static function Inc(t: Tree): Tree +function Inc(t: Tree): Tree { match t case Node(n, children) => Tree.Node(n+1, ForestInc(children)) } -static function ForestInc(forest: List): List +function ForestInc(forest: List): List { match forest case Nil => forest @@ -24,13 +24,13 @@ static function ForestInc(forest: List): List datatype GTree = Node(T, List>); -static function GInc(t: GTree): GTree +function GInc(t: GTree): GTree { match t case Node(n, children) => GTree.Node(n+1, GForestInc(children)) } -static function GForestInc(forest: List>): List> +function GForestInc(forest: List>): List> { match forest case Nil => forest @@ -43,13 +43,13 @@ datatype TreeList = Nil | Cons(OneTree, TreeList); datatype OneTree = Node(int, TreeList); -static function XInc(t: OneTree): OneTree +function XInc(t: OneTree): OneTree { match t case Node(n, children) => OneTree.Node(n+1, XForestInc(children)) } -static function XForestInc(forest: TreeList): TreeList +function XForestInc(forest: TreeList): TreeList { match forest case Nil => forest -- cgit v1.2.3