Пример #1
0
        public static ILispNode Concat(ILispNode functor, IList <ILispNode> arguments, CallStack callStack, params object [] args)
        {
#if TRACE_FLOW
            try
            {
#endif
            var merger = new AtomMerger(new LispMissing(), (r, x) => (((string)r).Unquote() + ((string)x).Unquote()).Quote());

            var result = functor.MergeAsString(arguments, callStack, 2, merger);

            return((merger.MissingSymbols.Count() > 0)
                    ? merger.MissingSymbols
                    : result);

#if TRACE_FLOW
        }

        catch (Exception ex)
        {
            Console.WriteLine("concat throws: " + ex.Message);
            throw;
        }
        finally
        {
            Console.WriteLine("(concat {0}) done", arguments.ToLispArgString());
        }
#endif
        }
Пример #2
0
        public static ILispNode SubDate(ILispNode functor, IList <ILispNode> arguments, CallStack callStack, params object [] args)
        {
#if TRACE_FLOW
            try
            {
#endif
            var merger = new AtomMerger(new LispMissing(), (r, x) => (DateTime)r - (TimeSpan)x);

            var result = functor.MergeAsDateTime(arguments, callStack, 2, merger);

            return((merger.MissingSymbols.Count() > 0)
                    ? merger.MissingSymbols
                    : result);

#if TRACE_FLOW
        }

        catch (Exception ex)
        {
            Console.WriteLine("sub_date throws: " + ex.Message);
            throw;
        }
        finally
        {
            Console.WriteLine("(sub_date {0}) done", arguments.ToLispArgString());
        }
#endif
        }
Пример #3
0
        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
        }
Пример #4
0
        public static ILispNode Not(ILispNode functor, IList <ILispNode> arguments, CallStack callStack, params object [] args)
        {
#if TRACE_FLOW
            try
            {
#endif
            try
            {
                var merger = new AtomMerger(new LispMissing(), (r, x) => !(bool)x);

                var result = functor.MergeAsBoolean(arguments, callStack, 1, merger);

                return((merger.MissingSymbols.Count() > 0)
                        ? merger.MissingSymbols
                        : result);
            }
            catch
            {
                throw new Exception("NOT requires its single argument to be Boolean");
            }
#if TRACE_FLOW
        }

        catch (Exception ex)
        {
            Console.WriteLine("not threw Exception: " + ex.Message);
            throw;
        }
        finally
        {
            Console.WriteLine("(not {0}) done", arguments.ToLispArgString());
        }
#endif
        }
Пример #5
0
        public static ILispNode Neq(ILispNode functor, IList <ILispNode> arguments, CallStack callStack, params object [] args)
        {
            #region DateTime

            try
            {
                var merger = new AtomMerger(new LispMissing());
                var walker = new DateTimeWalker("!=");

                var result = functor.WalkAsBoolean(arguments, callStack, 2, merger, walker);

                return((merger.MissingSymbols.Count() > 0)
                    ? merger.MissingSymbols
                    : result);
            }
            catch {}

            #endregion

            try
            {
                var merger = new AtomMerger(new LispMissing());
                var walker = new NumberWalker("!=");

                var result = functor.WalkAsBoolean(arguments, callStack, 2, merger, walker);

                return((merger.MissingSymbols.Count() > 0)
                    ? merger.MissingSymbols
                    : result);
            }
            catch {}

            try
            {
                var merger = new AtomMerger(new LispMissing());
                var walker = new BooleanWalker("!=");

                var result = functor.WalkAsBoolean(arguments, callStack, 2, merger, walker);

                return((merger.MissingSymbols.Count() > 0)
                    ? merger.MissingSymbols
                    : result);
            }
            catch {}

            try
            {
                var merger = new AtomMerger(new LispMissing());
                var walker = new StringWalker("!=");

                var result = functor.WalkAsBoolean(arguments, callStack, 2, merger, walker);

                return((merger.MissingSymbols.Count() > 0)
                    ? merger.MissingSymbols
                    : result);
            }
            catch {}

            throw new Exception("!= requires all arguments to be dates, numbers, booleans or strings");
        }
Пример #6
0
        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
        }
Пример #7
0
        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
        }
Пример #8
0
        public static ILispNode Unique(ILispNode functor, IList <ILispNode> arguments, CallStack callStack, params object [] args)
        {
            var Values = arguments.Select(x => x.Eval(callStack, true)).ToList();

            try
            {
                Values.Sort((x, y) => (x as LispAtom).ValueAsDateTime.CompareTo((y as LispAtom).ValueAsDateTime));

                var merger = new AtomMerger(new LispMissing());
                var walker = new DateTimeWalker((r, prev, curr) => { return(((bool)r) && (LispAtom.CastToDateTime(prev) != LispAtom.CastToDateTime(curr))); });

                var result = functor.WalkAsBoolean(Values, callStack, 2, merger, walker);

                return((merger.MissingSymbols.Count() > 0)
                    ? merger.MissingSymbols
                    : result);
            }
            catch {}

            try
            {
                Values.Sort(
                    (x, y) => ((x as LispAtom).ValueAsNumber < (y as LispAtom).ValueAsNumber)
                        ? -1
                        : +1);

                var merger = new AtomMerger(new LispMissing());
                var walker = new NumberWalker((r, prev, curr) => { return(((bool)r) && (LispAtom.CastToNumber(prev) != LispAtom.CastToNumber(curr))); });

                var result = functor.WalkAsBoolean(Values, callStack, 2, merger, walker);

                return((merger.MissingSymbols.Count() > 0)
                    ? merger.MissingSymbols
                    : result);
            }
            catch {}

            try
            {
                Values.Sort((x, y) => (String.Compare((x as LispAtom).ValueAsBoolean.ToString(), (y as LispAtom).ValueAsBoolean.ToString(), true)));

                var merger = new AtomMerger(new LispMissing());
                var walker = new BooleanWalker((r, prev, curr) => { return((bool)r && (LispAtom.CastToBoolean(prev) != LispAtom.CastToBoolean(curr))); });

                var result = functor.WalkAsBoolean(Values, callStack, 2, merger, walker);

                return((merger.MissingSymbols.Count() > 0)
                    ? merger.MissingSymbols
                    : result);
            }
            catch {}

            try
            {
                Values.Sort((x, y) => String.Compare((x as LispAtom).ValueAsString, (y as LispAtom).ValueAsString, true));

                var merger = new AtomMerger(new LispMissing());
                var walker = new StringWalker((r, prev, curr) => { return(((bool)r) && (LispAtom.CastToString(prev) != LispAtom.CastToString(curr))); });

                var result = functor.WalkAsBoolean(Values, callStack, 2, merger, walker);

                return((merger.MissingSymbols.Count() > 0)
                    ? merger.MissingSymbols
                    : result);
            }
            catch {}

            return(new LispAtom(true));
            //throw new Exception("UNIQUE requires all arguments to be dates, numbers or strings");
        }