/* Iterator pattern in Chalice. */ class List module Collections { var contents: seq; method init() requires acc(contents); ensures valid && size()==0; { contents := nil; fold valid; } method add(x: int) requires valid; ensures valid && size() == old(size()+1) && get(size()-1) == x; // I don't know why this happens. ensures forall i in [0..size()-1] :: get(i) == old(get(i)); { unfold valid; contents := contents ++ [x]; fold valid; } function get(index: int): int requires rd(valid) && 0<=index && index