package mfl;

public class List
extends mfl.Value
{
  public Value count_op()
    {return new mfl.Integer(size());}

  public boolean equals(Object x)
    {if (!(x instanceof List)) return false;
     int n = size();
     if (n != ((mfl.Value)x).size()) return false;
     for (int i = 1; i <= n; i++) if (!ith_element(i).equals(((mfl.Value)x).ith_element(i))) return false;
     return true;}

  public mfl.Value index_op(mfl.Value x, mfl.Value y)
    {int i, j; mfl.Enumerated_list result;
    if (!(x instanceof mfl.Integer)) return super.index_op(x, y);
    if (!(y instanceof mfl.Integer)) return super.index_op(x, y);
    i = (int)((mfl.Integer)x).java_value; j = (int)((mfl.Integer)y).java_value;
    if (i < 1) return super.index_op(x, y);
    if (i > size()) return super.index_op(x, y);
    if (j < i) return super.index_op(x, y);
    if (j > size()) j = size();
    result = new Enumerated_list(j - i + 1);
    while (i <= j) result.append(ith_element(i++));
    return result;}

  public Value plus_op(Value x)
    {int m, n; mfl.Enumerated_list result;
     m = size(); n = x.size();
     result = new Enumerated_list(m+n);
     for (int i = 1; i <= m; i++) result.append(ith_element(i));
     for (int i = 1; i <= n; i++) result.append(x.ith_element(i));
     return result;}
}

