Beispiel #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));
     }
 }
Beispiel #2
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);
     }
 }
Beispiel #4
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);
     }
 }
Beispiel #5
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);
     }
 }
Beispiel #6
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);
     }
 }
Beispiel #7
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);
         }
     }
 }
Beispiel #8
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);
         }
     }
 }
Beispiel #9
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);
            }
        }
Beispiel #10
0
 public static bool HasA <T1, T2>(this IStackList <object> stack)
 {
     return(stack.HasA <T1>(0) && stack.HasA <T2>(1));
 }