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); }
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); }
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)); }
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())); } }
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; }
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; }
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); }
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()); } }