Пример #1
0
 public static Obj CreateSeq(long[] vals, int len)
 {
     if (len != 0)
     {
         return(IntArrayObjs.Create(vals, len));
     }
     else
     {
         return(EmptySeqObj.singleton);
     }
 }
Пример #2
0
 public static Obj CreateSeq(long[] vals)
 {
     if (vals.Length != 0)
     {
         return(IntArrayObjs.Create(vals));
     }
     else
     {
         return(EmptySeqObj.singleton);
     }
 }
Пример #3
0
        public static TaggedObj CreateString(char[] chars, int len)
        {
            if (len == 0)
            {
                return(new TaggedObj(SymbObj.StringSymbId, EmptySeqObj.singleton));
            }

            int max = 0;

            for (int i = 0; i < len; i++)
            {
                char ch = chars[i];
                if (ch > max)
                {
                    max = ch;
                }
            }

            Obj charArray;

            if (max <= 255)
            {
                byte[] bytes = new byte[len];
                for (int i = 0; i < len; i++)
                {
                    bytes[i] = (byte)chars[i];
                }
                charArray = IntArrayObjs.Create(bytes);
            }
            else if (max <= 32767)
            {
                short[] shorts = new short[len];
                for (int i = 0; i < len; i++)
                {
                    shorts[i] = (short)chars[i];
                }
                charArray = IntArrayObjs.Create(shorts);
            }
            else
            {
                int[] ints = new int[len];
                for (int i = 0; i < len; i++)
                {
                    ints[i] = (int)chars[i];
                }
                charArray = IntArrayObjs.Create(ints);
            }

            return(new TaggedObj(SymbObj.StringSymbId, charArray));
        }
Пример #4
0
        public static Obj CreateSeq(Obj[] objs)
        {
            int len = objs.Length;

            if (len == 0)
            {
                return(EmptySeqObj.singleton);
            }

            if (objs[0].IsInt())
            {
                for (int i = 1; i < len; i++)
                {
                    if (!objs[i].IsInt())
                    {
                        return(ArrayObjs.Create(objs));
                    }
                }

                long[] longs = new long[len];
                for (int i = 0; i < len; i++)
                {
                    longs[i] = objs[i].GetLong();
                }
                return(IntArrayObjs.Create(longs));
            }

            if (objs[0].IsFloat())
            {
                for (int i = 1; i < len; i++)
                {
                    if (!objs[i].IsFloat())
                    {
                        return(ArrayObjs.Create(objs));
                    }
                }

                double[] doubles = new double[len];
                for (int i = 0; i < len; i++)
                {
                    doubles[i] = objs[i].GetDouble();
                }
                return(FloatArrayObjs.Create(doubles));
            }

            return(ArrayObjs.Create(objs));
        }
Пример #5
0
        public static Obj CreateSeq(Obj[] objs, int len)
        {
            if (len == 0)
            {
                return(EmptySeqObj.singleton);
            }

            for (int i = 0; i < len; i++)
            {
                if (!objs[i].IsInt())
                {
                    return(ArrayObjs.Create(objs, len));
                }
            }

            long[] longs = new long[len];
            for (int i = 0; i < len; i++)
            {
                longs[i] = objs[i].GetLong();
            }
            return(IntArrayObjs.Create(longs));
        }