Exemple #1
0
        // APPLY
        public static object Apply(object op, params object [] operands)
        {
            if (operands == null)
            {
                return(ResolveFunctionSpecifier(op).DynamicInvoke());
            }
            else if (operands.Length == 0)
            {
                return(ResolveFunctionSpecifier(op).DynamicInvoke());
            }
            Cons arglist = (Cons)operands [operands.Length - 1];

            for (int i = operands.Length - 2; i > -1; i--)
            {
                arglist = CL.Cons(operands [i], arglist);
            }
            int limit = CL.Length(arglist);

            object [] argarray = new object [limit];

            for (int i = 0; i < limit; i++)
            {
                argarray [i] = arglist.Car;
                arglist      = (Cons)arglist.Cdr;
            }
            return(ResolveFunctionSpecifier(op).DynamicInvoke((object)argarray));
        }
Exemple #2
0
        static public int Position(object item, object sequence)
        {
            if (sequence == null)
            {
                return(-1);
            }
            Cons list = sequence as Cons;

            if (list != null)
            {
                return(Position(item, list));
            }
            return(Position(item, sequence,
                            KW.FromEnd, false,
                            KW.Key, new Function1(CL.Identity),
                            KW.Test, new EqualityTest(CL.Eql),
                            KW.Start, 0,
                            KW.End, CL.Length(sequence)));
        }
Exemple #3
0
        static int Position(object item, object sequence, object [] arguments)
        {
            KeywordArgument <bool>   fromEnd = new KeywordArgument <bool> (KW.FromEnd);
            KeywordArgument <object> test    = new KeywordArgument <object> (KW.Test);
            KeywordArgument <int>    start   = new KeywordArgument <int> (KW.Start);
            KeywordArgument <int>    end     = new KeywordArgument <int> (KW.End);
            KeywordArgument <object> key     = new KeywordArgument <object> (KW.Key);

            KeywordArgumentBase.ProcessKeywordArguments(
                new KeywordArgumentBase [] { fromEnd, test, start, end, key },
                arguments,
                false);

            return(Position(item, sequence,
                            fromEnd.Supplied ? fromEnd.Value : false,
                            test.Supplied ? ResolveFunctionSpecifier <EqualityTest> (test.Value) : new EqualityTest(CL.Eql),
                            start.Supplied ? start.Value : 0,
                            end.Supplied ? end.Value : CL.Length(sequence),
                            key.Supplied ? ResolveFunctionSpecifier <Function1> (key.Value) : new Function1(CL.Identity)));
        }
Exemple #4
0
        static TItem Find <TItem, Tkey> (Tkey item, System.Collections.Generic.ICollection <TItem> sequence, object [] arguments)
        {
            KeywordArgument <bool>   fromEnd = new KeywordArgument <bool> (KW.FromEnd);
            KeywordArgument <object> test    = new KeywordArgument <object> (KW.Test);
            KeywordArgument <int>    start   = new KeywordArgument <int> (KW.Start);
            KeywordArgument <int>    end     = new KeywordArgument <int> (KW.End);
            KeywordArgument <object> key     = new KeywordArgument <object> (KW.Key);

            KeywordArgumentBase.ProcessKeywordArguments(
                new KeywordArgumentBase [] { fromEnd, test, start, end, key },
                arguments,
                false);
            if (!key.Supplied)
            {
                throw new NotImplementedException();
            }
            return(Find <TItem, Tkey> (item, sequence,
                                       fromEnd.Supplied ? fromEnd.Value : false,
                                       test.Supplied ? ResolveFunctionSpecifier <EqualityTest <Tkey> > (test.Value) : new EqualityTest <Tkey> (CL.Eql <Tkey>),
                                       start.Supplied ? start.Value : 0,
                                       end.Supplied ? end.Value : CL.Length(sequence),
                                       ResolveFunctionSpecifier <Function1 <Tkey, TItem> > (key.Value)));
        }