示例#1
0
        public static ILispNode Apply(ILispNode functor, IList <ILispNode> arguments, CallStack callStack, params object[] args)
        {
#if TRACE_FLOW
            try
            {
#endif
            try
            {
                if (arguments.Count < 1)
                {
                    throw new Exception("MAP requires at least 1 argument");
                }

                var applyFunctor = arguments[0].Eval(callStack, args);

                return(Functor.Apply(applyFunctor, new LispList(null, arguments.Skip(1)), callStack, args));
            }
            catch
            {
                return(new LispNil());
            }
#if TRACE_FLOW
        }

        catch (Exception ex)
        {
            Console.WriteLine("apply threw Exception: " + ex.Message);
            throw;
        }
        finally
        {
            Console.WriteLine("(apply {0}) done", arguments.ToLispArgString());
        }
#endif
        }
示例#2
0
        public static ILispNode Map(ILispNode functor, IList <ILispNode> arguments, CallStack callStack, params object[] args)
        {
#if TRACE_FLOW
            try
            {
#endif
            try
            {
                if (arguments.Count < 1)
                {
                    throw new Exception("MAP requires at least 1 argument");
                }

                var result = new LispList();

                var mapFunctor = arguments[0].Eval(callStack, args);

                // run through the arguments list one at a time and map them to the result with the lambda
                arguments.Skip(1).ToList().ForEach(x => result.Add(Functor.Apply(mapFunctor, new LispList().Add(x), callStack, args)));

                return(result);
            }
            catch
            {
                return(new LispNil());
            }
#if TRACE_FLOW
        }

        catch (Exception ex)
        {
            Console.WriteLine("map threw Exception: " + ex.Message);
            throw;
        }
        finally
        {
            Console.WriteLine("(map {0}) done", arguments.ToLispArgString());
        }
#endif
        }