public static ILispNode Negate(ILispNode functor, IList <ILispNode> arguments, CallStack callStack, params object [] args) { #if TRACE_FLOW try { #endif try { var merger = new AtomMerger(new LispMissing(), (r, x) => - 1 * (double)x); var result = functor.MergeAsNumber(arguments, callStack, 1, merger); return((merger.MissingSymbols.Count() > 0) ? merger.MissingSymbols : result); } catch (Exception ex) { throw new LispException(null, "NEGATE throws exception!", ex); } #if TRACE_FLOW } catch (Exception ex) { Console.WriteLine("negate threw Exception: " + ex.Message); throw; } finally { Console.WriteLine("(negate {0}) done", arguments.ToLispArgString()); } #endif }
public static ILispNode AddNumber(ILispNode functor, IList <ILispNode> arguments, CallStack callStack, params object [] args) { #if TRACE_FLOW try { #endif var merger = new AtomMerger(new LispMissing(), (r, x) => (double)r + (double)x); var result = functor.MergeAsNumber(arguments, callStack, 2, merger); return((merger.MissingSymbols.Count() > 0) ? merger.MissingSymbols : result); #if TRACE_FLOW } catch (Exception ex) { Console.WriteLine("add_number throws: " + ex.Message); throw; } finally { Console.WriteLine("(add_number {0}) done", arguments.ToLispArgString()); } #endif }
public static ILispNode Prod(ILispNode functor, IList <ILispNode> arguments, CallStack callStack, params object [] args) { #if TRACE_FLOW try { #endif try { var merger = new AtomMerger(new LispMissing(), (r, x) => (double)r * (double)x); var result = functor.MergeAsNumber(arguments, callStack, 2, merger); return((merger.MissingSymbols.Count() > 0) ? merger.MissingSymbols : result); } catch { throw new Exception("PROD requires all arguments to be numbers"); } #if TRACE_FLOW } catch (Exception ex) { Console.WriteLine("prod threw Exception: " + ex.Message); throw; } finally { Console.WriteLine("(prod {0}) done", arguments.ToLispArgString()); } #endif }