public ILispValue execute(LispArray array) { int max_it = array.getSize(); List <ILispValue> tmp = new List <ILispValue> (); ILispValue ret; if (array.getSize() > 1) { for (int idx = 1; idx < max_it; idx++) { tmp.Add(array [idx].eval()); } if (tmp [0].getType() == ELispType.Floating) { if (tmp.Count == 1) { return(new LispFloating(-tmp [0].getFloating())); } double a = tmp [0].getFloating(); for (int idx = 1; idx < tmp.Count; idx++) { a -= tmp [idx].getFloating(); } ret = new LispFloating(a); } else { if (tmp.Count == 1) { return(new LispInteger(-tmp [0].getInteger())); } BigInteger a = tmp [0].getInteger(); for (int idx = 1; idx < tmp.Count; idx++) { a -= tmp [idx].getInteger(); } ret = new LispInteger(a); } return(ret); } else { return(new LispString("ERROR : - require at least one operand")); } }
public ILispValue execute(LispArray array) { int max_it = array.getSize(); List <ILispValue> tmp = new List <ILispValue> ();; ILispValue ret; if (array.getSize() > 1) { for (int idx = 1; idx < max_it; idx++) { tmp.Add(array [idx].eval()); } if (tmp [0].getType() == ELispType.Floating) { double a = 1; for (int idx = 0; idx < tmp.Count; idx++) { a *= tmp [idx].getFloating(); } ret = new LispFloating(a); } else if (tmp [0].getType() == ELispType.LispValue && tmp.Count == 1) { List <ILispValue> tmp2 = new List <ILispValue> (); for (int idx = 0; idx < ((LispArray)tmp[0]).getSize(); idx++) { tmp2.Add(((LispArray)tmp[0])[idx].eval()); } if (tmp2 [0].getType() == ELispType.Floating) { double a = 1; for (int idx = 0; idx < tmp2.Count; idx++) { a *= tmp2 [idx].getFloating(); } ret = new LispFloating(a); } else { BigInteger a = 1; for (int idx = 0; idx < tmp2.Count; idx++) { a *= tmp2 [idx].getInteger(); } ret = new LispInteger(a); } } else { BigInteger a = 1; for (int idx = 0; idx < tmp.Count; idx++) { a *= tmp [idx].getInteger(); } ret = new LispInteger(a); } return(ret); } else { return(new LispString("ERROR : * require at least one operand")); } }