!752

// A vessel is a list of strings (sentences).

sclass Vessel {
  new L<S> data;
  int index;

  *() {}
  *(L<S> *data, int *index) {}

  void add(S s) {
    data.add(simplify(s));
  }

  bool consume(S s) {
    if (end()) ret false;
    
    s = simplify(s);
    
    /*if (same(next(), s)) {
      ++index;
      ret true;
    }
    ret false;*/
    
    //++index;
    
    if (!same(next(), s)) {
      --index;
      ret false;
    }
    ret true;
  }

  void restart() {
    index = 0;
  }

  // may be null if index after end
  S next() {
    ret end() ? null : get(data, index++);
  }
  
  bool end() {
    ret index >= l(data);
  }

  public Vessel clone() {
    ret new Vessel(cloneList(data), index);
  }
}

static S simplify(S s) {
  ret s.trim().toUpperCase();
}

static bool same(S a, S b) {
  ret eq(a, b);
}

p {
  new Vessel v;
  v.add("hello");
  v.add("world");
  print("HELLO");
  assertTrue(v.consume("HELLO"));
  assertEquals(1, v.index);
  print("world? " + v.next());
  print("end? " + v.end());
}