예제 #1
0
파일: Lists.cs 프로젝트: lsgxeva/IronScheme
        internal static Cons ToImproper(Cons c)
        {
            Cons i = c;
            Cons j = null;

            while (i.cdr != null)
            {
                j = i;
                i = i.cdr as Cons;
                if (i == null)
                {
                    return(c); // improper already
                }
            }

            j.cdr = i.car;
            return(c);
        }
예제 #2
0
        public static object Apply(object fn, object list)
        {
            Cons     args = Requires <Runtime.Cons>(list);
            Callable c    = RequiresNotNull <Callable>(fn);

            if (args == null)
            {
                return(c.Call());
            }
            List <object> targs = new List <object>();

            while (args != null)
            {
                targs.Add(args.car);
                args = args.cdr as Cons;
            }

            return(c.Call(targs.ToArray()));
        }
예제 #3
0
파일: Cons.cs 프로젝트: lsgxeva/IronScheme
 public static Cons FromArray(params object[] args)
 {
     if (args == null)
     {
         return(null);
     }
     if (args.Length == 0)
     {
         return(null);
     }
     else if (args.Length == 1)
     {
         return(new Cons(args[0]));
     }
     else
     {
         return(Cons.FromList(args));
     }
 }
예제 #4
0
파일: Cons.cs 프로젝트: lsgxeva/IronScheme
        public static Cons FromList(IEnumerable list)
        {
            if (list == null)
            {
                return(null);
            }
            Cons first = null;
            Cons c     = null;

            foreach (object var in list)
            {
                if (c == null)
                {
                    first = c = new Cons(var);
                }
                else
                {
                    Cons d = new Cons(var);
                    c.cdr = d;
                    c     = d;
                }
            }
            return(first);
        }
예제 #5
0
 public static double[] ListToFlonumVector(Cons list)
 {
     return(ListToVector <double>(list));
 }
예제 #6
0
        public static object[] ListToVector(object args)
        {
            Cons e = Requires <Cons>(args);

            return(ListToVector(e));
        }
예제 #7
0
 public static int[] ListToFixnumVector(Cons list)
 {
     return(ListToVector <int>(list));
 }
예제 #8
0
        public override object Call(object[] args)
        {
            try
            {
                object ppo;

                if (Builtins.cc.Scope.TryLookupName(SymbolTable.StringToId("trace-printer"), out ppo))
                {
                    ppo = (ppo as Callable).Call();
                }
                else
                {
                    ppo = "write".Eval();
                }
                Callable pp = ppo as Callable;

                depth++;

                Cons c = Runtime.Cons.FromArray(args), u = c;

                if (filter != null)
                {
                    while (c != null)
                    {
                        c.car = filter.Call(c.car);
                        c     = c.cdr as Cons;
                    }
                }


                object a = args.Length == 1 ? Builtins.Car(u) : u;

                StringWriter pre = new StringWriter();

                pp.Call(a, pre);

                string prefix = new string('|', depth);

                if ((Console.LargestWindowWidth | Console.LargestWindowHeight) == 0)
                {
                    Console.WriteLine("{0} -> {1}", prefix, name);
                    Console.WriteLine(pre.GetBuffer().TrimEnd(Environment.NewLine.ToCharArray()));

                    object result = realtarget.Call(args);

                    StringWriter p = new StringWriter();

                    pp.Call(filter == null ? result : filter.Call(result), p);

                    Console.WriteLine("{0} <- {1}", prefix, name);
                    Console.WriteLine(p.GetBuffer().TrimEnd(Environment.NewLine.ToCharArray()));
                    return(result);
                }
                else
                {
                    Console.ForegroundColor = ConsoleColor.Yellow;
                    Console.WriteLine("{0} -> {1}", prefix, name);
                    Console.ForegroundColor = ConsoleColor.White;
                    Console.WriteLine(pre.GetBuffer().TrimEnd(Environment.NewLine.ToCharArray()));
                    Console.ForegroundColor = ConsoleColor.Gray;

                    object result = realtarget.Call(args);

                    StringWriter p = new StringWriter();

                    pp.Call(filter == null ? result : filter.Call(result), p);

                    Console.ForegroundColor = ConsoleColor.Cyan;
                    Console.WriteLine("{0} <- {1}", prefix, name);
                    Console.ForegroundColor = ConsoleColor.White;
                    Console.WriteLine(p.GetBuffer().TrimEnd(Environment.NewLine.ToCharArray()));
                    Console.ForegroundColor = ConsoleColor.Gray;
                    return(result);
                }
            }
            finally
            {
                depth--;
            }
        }