Example #1
0
        protected Variable Slice(Variable obj, Variable key)
        {
            if (key.Fetch().mo.HasType(Kernel.JunctionMO))
            {
                return(Builtins.AutoThread(key.Fetch(), delegate(Variable v) {
                    return Get(obj, v);
                }));
            }

            VarDeque        iter  = Builtins.start_iter(key);
            List <Variable> items = new List <Variable>();

            while (Kernel.IterHasFlat(iter, true))
            {
                items.Add(Get(obj, iter.Shift()));
            }
            // TODO: 1-element slices should be deparceled.  Requires
            // LISTSTORE improvements though.
            return(Kernel.NewRWListVar(Kernel.BoxRaw <Variable[]>(
                                           items.ToArray(), Kernel.ParcelMO)));
        }