示例#1
0
        public static object ReadVectorHandler2(LispReader stream, string ch, int arg)
        {
            if (stream.ReadChar() != '(')
            {
                throw stream.MakeScannerException("Invalid #() expression");
            }
            var list = stream.ReadDelimitedList(")");
            var obj  = new Vector();

            obj.AddRange(list);
            if (arg == -1)
            {
                // default no action
            }
            else if (arg < obj.Count)
            {
                throw new LispException("Vector {0} contains more than {1} items", ToPrintString(obj), arg);
            }
            else if (arg > obj.Count)
            {
                var filler = obj.Count == 0 ? (object)null : obj[obj.Count - 1];
                while (obj.Count < arg)
                {
                    obj.Add(filler);
                }
            }
            return(obj);
        }
示例#2
0
        public static object ReadStructHandler(LispReader stream, string ch, int arg)
        {
            if (stream.ReadChar() != '(')
            {
                throw stream.MakeScannerException("Invalid #s() expression");
            }
            var list = stream.ReadDelimitedList(")");
            var obj  = new Prototype(AsArray(list));

            return(obj);
        }
示例#3
0
        public static object ReadComplexNumberHandler(LispReader stream, string ch, int arg)
        {
            if (stream.ReadChar() != '(')
            {
                throw stream.MakeScannerException("Invalid #c expression");
            }
            var    nums  = stream.ReadDelimitedList(")");
            int    count = Length(nums);
            double real  = count >= 1 ? AsDouble(nums.Car) : 0;
            double imag  = count >= 2 ? AsDouble(nums.Cdr.Car) : 0;

            return(new Complex(real, imag));
        }
示例#4
0
        public static object ReadCommaHandler(LispReader stream, char ch)
        {
            var ch2 = stream.ReadChar();

            if (ch2 == '@' || ch2 == '.')
            {
                // Destructive splicing is handled as ordinary splicing
                return(MakeList(Symbols.UnquoteSplicing, stream.Read()));
            }
            else
            {
                stream.UnreadChar();
                return(MakeList(Symbols.Unquote, stream.Read()));
            }
        }
示例#5
0
 public static object ReadVectorHandler2(LispReader stream, string ch, int arg)
 {
     if (stream.ReadChar() != '(')
     {
         throw stream.MakeScannerException("Invalid #() expression");
     }
     var list = stream.ReadDelimitedList(")");
     var obj = new Vector();
     obj.AddRange(list);
     if (arg == -1)
     {
         // default no action
     }
     else if (arg < obj.Count)
     {
         throw new LispException("Vector {0} contains more than {1} items", ToPrintString(obj), arg);
     }
     else if (arg > obj.Count)
     {
         var filler = obj.Count == 0 ? (object)null : obj[obj.Count - 1];
         while (obj.Count < arg)
         {
             obj.Add(filler);
         }
     }
     return obj;
 }
示例#6
0
 public static object ReadStructHandler(LispReader stream, string ch, int arg)
 {
     if (stream.ReadChar() != '(')
     {
         throw stream.MakeScannerException("Invalid #s() expression");
     }
     var list = stream.ReadDelimitedList(")");
     var obj = new Prototype(AsArray(list));
     return obj;
 }
示例#7
0
 public static object ReadComplexNumberHandler(LispReader stream, string ch, int arg)
 {
     if (stream.ReadChar() != '(')
     {
         throw stream.MakeScannerException("Invalid #c expression");
     }
     var nums = stream.ReadDelimitedList(")");
     int count = Length(nums);
     double real = count >= 1 ? AsDouble(nums.Car) : 0;
     double imag = count >= 2 ? AsDouble(nums.Cdr.Car) : 0;
     return new Complex(real, imag);
 }
示例#8
0
        public static object ReadCommaHandler(LispReader stream, char ch)
        {
            var ch2 = stream.ReadChar();

            if (ch2 == '@' || ch2 == '.')
            {
                // Destructive splicing is handled as ordinary splicing
                return MakeList(Symbols.UnquoteSplicing, stream.Read());
            }
            else
            {
                stream.UnreadChar();
                return MakeList(Symbols.Unquote, stream.Read());
            }
        }