Esempio n. 1
0
 public static void Sample(IStackList<object> stack)
 {
     if (stack.HasA<int, IEnumerable<double>>())
     {
         var limit = stack.Pop<int>();
         var seq = stack.Pop<IEnumerable<double>>();
         stack.Push(seq.Take(limit));
     }
 }
Esempio n. 2
0
 public static void Merge(IStackList<object> stack)
 {
     if (stack.HasA<IEnumerable<double>, IEnumerable<double>>())
     {
         var seq1 = stack.Pop<IEnumerable<double>>();
         var seq2 = stack.Pop<IEnumerable<double>>();
         var result = seq1.Zip(seq2, (a, b) => a + b);
         stack.Push(result);
     }
 }
Esempio n. 3
0
 public static void Concat(IStackList<object> stack)
 {
     if (stack.HasA<IEnumerable<double>, IEnumerable<double>>())
     {
         var seq1 = stack.Pop<IEnumerable<double>>();
         var seq2 = stack.Pop<IEnumerable<double>>();
         var result = seq2.Concat(seq1);
         stack.Push(result);
     }
 }
Esempio n. 4
0
 public static void Drop(IStackList <object> stack)
 {
     if (stack.Count > 0)
     {
         stack.Pop();
     }
 }
Esempio n. 5
0
 public static void Swap(IStackList <object> stack)
 {
     if (stack.Count > 1)
     {
         var obj = stack.Pop();
         stack.Insert(1, obj);
     }
 }
Esempio n. 6
0
 public static void Cycle(IStackList<object> stack)
 {
     if (stack.HasA<IEnumerable<double>>())
     {
         var seq = stack.Pop<IEnumerable<double>>();
         seq = seq.AsCycle();
         stack.Push(seq);
     }
 }
 public static void Load(IStackList <object> stack)
 {
     if (stack.HasA <string>())
     {
         var name = stack.Pop <string>();
         var seq  = SequenceFactory.Load(name);
         stack.Push(seq);
     }
 }
Esempio n. 8
0
 public static void Saw(IStackList<object> stack)
 {
     if (stack.HasA<int>())
     {
         var x = 0;
         var width = stack.Pop<int>();
         var seq = SequenceFactory.From(() => Math.Pow(x++ % width, 2));
         stack.Push(seq);
     }
 }
Esempio n. 9
0
 public static void Roll(IStackList <object> stack)
 {
     if (stack.HasA <int>())
     {
         var i = stack.Pop <int>();
         if (i <= stack.Count)
         {
             for (var j = 0; j < i; j++)
             {
                 var obj = stack.Pop();
                 stack.Add(obj);
             }
         }
         else
         {
             stack.Push(i);
         }
     }
 }
Esempio n. 10
0
        public static void Map(IStackList<object> stack)
        {
            if (stack.HasA<string, IEnumerable<double>>())
            {
                var expr = stack.Pop<string>();
                var seq = stack.Pop<IEnumerable<double>>();

                var ctx = new ExpressionContext();
                ctx.Imports.AddType(typeof(Math));
                ctx.Imports.AddType(typeof(Probability));
                ctx.Variables["x"] = 0.0;
                var gexpr = ctx.CompileGeneric<double>(expr);

                var result = seq.Select(x =>
                {
                    ctx.Variables["x"] = x;
                    return gexpr.Evaluate();
                });
                stack.Push(result);
            }
        }
Esempio n. 11
0
        public static T Pop <T>(this IStackList <object> stack)
        {
            var item = stack.Pop();

            if (typeof(T).IsAssignableFrom(item.GetType()))
            {
                return((T)item);
            }
            else
            {
                return((T)Convert.ChangeType(item, typeof(T)));
            }
        }
Esempio n. 12
0
 public static void Pick(IStackList <object> stack)
 {
     if (stack.HasA <int>())
     {
         var i = stack.Pop <int>();
         if (i > stack.Count)
         {
             var obj = stack[i];
             stack.Remove(obj);
             stack.Push(obj);
         }
         else
         {
             stack.Push(i);
         }
     }
 }