Beispiel #1
0
        public ISliceable Slice(Context context, IntegerValue fi, IntegerValue li)
        {
            long fi_ = (fi == null) ? 1L : fi.LongValue;

            if (fi_ < 0)
            {
                throw new IndexOutOfRangeError();
            }
            long li_ = (li == null) ? (long)Count : li.LongValue;

            if (li_ < 0)
            {
                li_ = Count + 1 + li_;
            }
            else if (li_ > Count)
            {
                throw new IndexOutOfRangeError();
            }
            TupleValue result = new TupleValue();
            long       idx    = 0;

            foreach (IValue e in this)
            {
                if (++idx < fi_)
                {
                    continue;
                }
                if (idx > li_)
                {
                    break;
                }
                result.Add(e);
            }
            return(result);
        }
Beispiel #2
0
 public IValue Add(Context context, IValue value)
 {
     if (value is TupleValue)
     {
         TupleValue result = new TupleValue();
         result.AddRange(this);
         result.AddRange((TupleValue)value);
         return(result);
     }
     else if (value is ListValue)
     {
         TupleValue result = new TupleValue();
         result.AddRange(this);
         result.AddRange((ListValue)value);
         return(result);
     }
     else if (value is SetValue)
     {
         TupleValue result = new TupleValue();
         result.AddRange(this);
         result.AddRange(((SetValue)value).getItems());
         return(result);
     }
     else
     {
         throw new SyntaxError("Illegal: Tuple + " + value.GetType().Name);
     }
 }
Beispiel #3
0
        public Int32 CompareTo(Context context, TupleValue other, List <bool> directions)
        {
            IEnumerator <bool>   iterDirs  = directions.GetEnumerator();
            IEnumerator <IValue> iterThis  = this.GetEnumerator();
            IEnumerator <IValue> iterOther = other.GetEnumerator();

            while (iterThis.MoveNext())
            {
                bool descending = iterDirs.MoveNext() ? iterDirs.Current : false;
                if (iterOther.MoveNext())
                {
                    // compare items
                    IValue thisVal  = iterThis.Current;
                    IValue otherVal = iterOther.Current;
                    if (thisVal == null && otherVal == null)
                    {
                        continue;
                    }
                    else if (thisVal == null)
                    {
                        return(descending ? 1 : -1);
                    }
                    else if (otherVal == null)
                    {
                        return(descending ? -1 : 1);
                    }
                    int cmp = thisVal.CompareTo(context, otherVal);
                    // if not equal, done
                    if (cmp != 0)
                    {
                        return(descending ? -cmp : cmp);
                    }
                }
                else
                {
                    return(descending ? -1 : 1);
                }
            }
            bool desc2 = iterDirs.MoveNext() ? iterDirs.Current : false;

            if (iterOther.MoveNext())
            {
                return(desc2 ? 1 : -1);
            }
            else
            {
                return(0);
            }
        }