Inheritance: APersistentVector, IObj, IEditableCollection, IEnumerable, IReduce
Ejemplo n.º 1
0
 public ChunkedSeq(PersistentVector vec, int i, int offset)
 {
     _vec    = vec;
     _i      = i;
     _offset = offset;
     _node   = vec.ArrayFor(i);
 }
Ejemplo n.º 2
0
        static public PersistentVector create(ISeq items)
        {
            Object[] arr = new Object[32];
            int      i   = 0;

            for (; items != null && i < 32; items = items.next())
            {
                arr[i++] = items.first();
            }

            if (items != null)
            {
                // >32, construct with array directly
                PersistentVector start = new PersistentVector(32, 5, EmptyNode, arr);
                TransientVector  ret   = (TransientVector)start.asTransient();
                for (; items != null; items = items.next())
                {
                    ret = (TransientVector)ret.conj(items.first());
                }
                return((PersistentVector)ret.persistent());
            }
            else if (i == 32)
            {
                // exactly 32, skip copy
                return(new PersistentVector(32, 5, EmptyNode, arr));
            }
            else
            {
                // <32, copy to minimum array and construct
                Object[] arr2 = new Object[i];
                Array.Copy(arr, 0, arr2, 0, i);

                return(new PersistentVector(i, 5, EmptyNode, arr2));
            }
        }
Ejemplo n.º 3
0
 public ChunkedSeq(PersistentVector vec, object[] node, int i, int offset)
 {
     _vec    = vec;
     _node   = node;
     _i      = i;
     _offset = offset;
 }
Ejemplo n.º 4
0
 public static DataSeries AddNewCurrentDataSeries(PersistentVector initialPoints, string name, Color? color)
 {
     DataSeries ds = new DataSeries(Utility.PVtoGPList(initialPoints), name, color);
     CurrentDataSeries = AllDataSeries.Count - 1;
     UpdateSeriesInfoInUI();
     return ds;
 }
Ejemplo n.º 5
0
 ChunkedSeq(IPersistentMap meta, PersistentVector vec, object[] node, int i, int offset)
     : base(meta)
 {
     _vec    = vec;
     _node   = node;
     _i      = i;
     _offset = offset;
 }
Ejemplo n.º 6
0
 static public IPersistentVector create(System.Collections.ICollection coll)
 {
     if (!(coll is ISeq) && coll.Count <= 32)
     {
         object[] array = new object[coll.Count];
         coll.CopyTo(array, 0);
         return(createOwning(array));
     }
     return(PersistentVector.create(RT.seq(coll)));
 }
        static public IPersistentVector createOwning(params object[] items)
        {
            //if (items.Length <= Tuple.MAX_SIZE)
            //    return Tuple.createFromArray(items);
            //else
            if (items.Length <= 32)
            {
                return(new PersistentVector(items.Length, 5, PersistentVector.EmptyNode, items));
            }
            return(PersistentVector.create(items));

            //: new LazilyPersistentVector(null, items, null);
        }
Ejemplo n.º 8
0
        public static void AddClojureButtons(PersistentVector vec)
        {
            List<Button> buttons = new List<Button>();

            for (int i = 0; i < vec.Count; i += 2)
            {
                if (!(vec[i + 1] is IFn))
                    continue;
                buttons.Add(CreateClojureButton(vec[i].ToString(), (IFn)vec[i + 1]));
            }

            ClojureDefinedUI.self.AddNewClojureControls(buttons.ToArray());
        }
Ejemplo n.º 9
0
        static public IPersistentVector createOwning(params object[] items)
        {
            if (items.Length == 0)
            {
                return((IPersistentVector)PersistentVector.EMPTY);
            }
            else if (items.Length <= 32)
            {
                return(new PersistentVector(items.Length, 5, PersistentVector.EmptyNode, items));
            }
            return(PersistentVector.create(items));

            //: new LazilyPersistentVector(null, items, null);
        }
Ejemplo n.º 10
0
        public static List<GraphPoint> PVtoGPList(PersistentVector pv)
        {
            List<GraphPoint> points = new List<GraphPoint>();

            int count = 0;
            foreach (object obj in pv)
            {
                if (count > ClojureEngine.ClojureMaxIterations)
                    break;

                try
                {
                    points.Add((GraphPoint)obj);
                    ++count;
                }
                catch { }
            }

            return points;
        }
Ejemplo n.º 11
0
        public static void AddClojureDropDownBox(string labelText, Var variable, PersistentVector vals, IFn func)
        {
            string variableSymbolName = null;

            if(variable != null)
                variableSymbolName = variable.sym.Name;

            Label label = new Label();
            label.AutoSize = true;
            label.Text = labelText;

            Dictionary<string, object> labelCodeAssoc = new Dictionary<string, object>();

            ComboBox comboBox = new ComboBox();
            for (int i = 0; i < vals.Count; i += 2)
            {
                labelCodeAssoc.Add(vals[i].ToString(), vals[i + 1]);
                comboBox.Items.Add(vals[i]);
            }

            comboBox.SelectedIndex = 0;
            comboBox.DropDownStyle = ComboBoxStyle.DropDownList;
            comboBox.SelectedIndexChanged += (s, e) =>
                {
                    if (comboBox.SelectedItem == null)
                        return;

                    object code = labelCodeAssoc[comboBox.SelectedItem.ToString()];

                     if(variableSymbolName != null)
                    {
                        string newVal = code.ToString();
                        ClojureEngine.Eval("(def " + variableSymbolName + " " + newVal + ")");
                    }

                    if (func != null)
                        ClojureEngine.Log(func.invoke());
                };

            self.AddNewClojureControls(new Control[] { label, comboBox });
        }
Ejemplo n.º 12
0
        static public IPersistentVector create(object obj)
        {
            //if ((obj is Counted || RT.SupportsRandomAccess(obj))
            //    && fcount(obj) <= Tuple.MAX_SIZE)
            //    return Tuple.createFromColl(obj);

            if (obj is IReduceInit ri)
            {
                return(PersistentVector.create(ri));
            }
            if (obj is ISeq)
            {
                return(PersistentVector.create(RT.seq(obj)));
            }

            if (obj is IEnumerable ie)
            {
                return(PersistentVector.create1(ie));
            }

            return(createOwning(RT.toArray(obj)));
        }
Ejemplo n.º 13
0
 public static void CreateButton(PersistentVector vec)
 {
     ClojureDefinedUI.AddClojureButtons(vec);
 }
Ejemplo n.º 14
0
 public TransientVector(PersistentVector v)
     : this(v._cnt, v._shift, EditableRoot(v._root), EditableTail(v._tail))
 {
 }
Ejemplo n.º 15
0
 ChunkedSeq(IPersistentMap meta, PersistentVector vec, object[] node,  int i, int offset)
     : base(meta)
 {
     _vec = vec;
     _node = node;
     _i = i;
     _offset = offset;
 }
Ejemplo n.º 16
0
 public ChunkedSeq(PersistentVector vec, object[] node,  int i, int offset)
 {
     _vec = vec;
     _node = node;
     _i = i;
     _offset = offset;
 }
Ejemplo n.º 17
0
 public ChunkedSeq(PersistentVector vec, int i, int offset)
 {
     _vec = vec;
     _i = i;
     _offset = offset;
     _node = vec.ArrayFor(i);
 }
Ejemplo n.º 18
0
 public static void CreateDropdown(string label, Var var, PersistentVector keyvaluepairs, IFn func)
 {
     ClojureDefinedUI.AddClojureDropDownBox(label, var, keyvaluepairs, func);
 }
Ejemplo n.º 19
0
 /// <summary>
 /// Constructs a lazily persistent vector.
 /// </summary>
 /// <param name="meta">The metadata to attach.</param>
 /// <param name="array">The array of values.</param>
 /// <param name="v">The accompanying persistent vector.</param>
 LazilyPersistentVector(IPersistentMap meta, object[] array, PersistentVector v)
     : base(meta)
 {
     _array = array;
     _v     = v;
 }
Ejemplo n.º 20
0
        public static PersistentVector create(ISeq items)
        {
            Object[] arr = new Object[32];
            int i = 0;
            for (; items != null && i < 32; items = items.next())
                arr[i++] = items.first();

            if (items != null)
            {
                // >32, construct with array directly
                PersistentVector start = new PersistentVector(32, 5, EmptyNode, arr);
                TransientVector ret = (TransientVector)start.asTransient();
                for (; items != null; items = items.next())
                    ret = (TransientVector)ret.conj(items.first());
                return (PersistentVector)ret.persistent();
            }
            else if (i == 32)
            {
                // exactly 32, skip copy
                return new PersistentVector(32, 5, EmptyNode, arr);
            }
            else
            {
                // <32, copy to minimum array and construct
                Object[] arr2 = new Object[i];
                Array.Copy(arr, 0, arr2, 0, i);

                return new PersistentVector(i, 5, EmptyNode, arr2);
            }
        }
Ejemplo n.º 21
0
 public TransientVector(PersistentVector v)
     : this(v._cnt, v._shift, EditableRoot(v._root), EditableTail(v._tail))
 {
 }
Ejemplo n.º 22
0
 public static DataSeries AddNewCurrentDataSeries(PersistentVector initialPoints, string name)
 {
     return AddNewCurrentDataSeries(initialPoints, name, null);
 }
Ejemplo n.º 23
0
 public static void CreateDropdownFn(string label, PersistentVector keyvaluepairs)
 {
     ClojureDefinedUI.AddClojureDropDownBoxFn(label, null, keyvaluepairs, null);
 }
Ejemplo n.º 24
0
 public static DataSeries AddNewSeries(PersistentVector initialPoints)
 {
     return AddNewSeries(initialPoints, null, null);
 }
 /// <summary>
 /// Constructs a lazily persistent vector.
 /// </summary>
 /// <param name="meta">The metadata to attach.</param>
 /// <param name="array">The array of values.</param>
 /// <param name="v">The accompanying persistent vector.</param>
 LazilyPersistentVector(IPersistentMap meta, object[] array, PersistentVector v)
     : base(meta)
 {
     _array = array;
     _v = v;
 }