Esempio n. 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));
        }
Esempio n. 2
0
        static Cons MapVectorToList1(object functionSpecifier, object [] sequence)
        {
            Delegate function = ResolveFunctionSpecifier(functionSpecifier);
            Cons     answer   = null;

            foreach (object element in sequence)
            {
                answer = Cons(function.DynamicInvoke(element), answer);
            }
            return((Cons)CL.Reverse(answer));
        }
Esempio n. 3
0
 public override ReaderStep NextStep()
 {
     if (this.package == null)
     {
         return(new FinalReaderStep(new Symbol(token)));
     }
     else
     {
         return(new FinalReaderStep(CL.Intern(token, package)));
     }
 }
Esempio n. 4
0
        static System.Collections.Generic.IList <T> MapVectorToList1 <I, T> (object functionSpecifier, I [] sequence)
        {
            Delegate           function = ResolveFunctionSpecifier(functionSpecifier);
            ConsCollection <T> answer   = null;

            foreach (I element in sequence)
            {
                answer = new ConsCollection <T> ((T)function.DynamicInvoke(element), answer);
            }
            return(CL.Reverse <T> (answer));
        }
Esempio n. 5
0
        static System.Collections.Generic.IList <T> MapCollectionToList1 <T> (object functionSpecifier, ICollection sequence)
        {
            Delegate           function      = ResolveFunctionSpecifier(functionSpecifier);
            ConsCollection <T> reverseAnswer = null;

            foreach (object element in sequence)
            {
                T item = (T)function.DynamicInvoke(element);
                reverseAnswer = new ConsCollection <T> (item, reverseAnswer);
            }
            return(CL.Reverse <T> (reverseAnswer));
        }
Esempio n. 6
0
        static public Cons RemArgs(object [] ra, object key)
        {
            Cons reversedAnswer = null;

            for (int i = 0; i < ra.Length; i += 2)
            {
                if (ra [i] != key)
                {
                    reversedAnswer = new Cons(ra [i + 1], new Cons(ra [i], reversedAnswer));
                }
            }
            return(CL.Reverse(reversedAnswer));
        }
Esempio n. 7
0
        public override ReaderStep NextStep()
        {
            if (CL.ReadSuppress)
            {
                // Toss the symbol and read the next thing.
                return(new InitialReaderStep(this.context));
            }

            // handle numbers here
            else
            {
                return(new TokenToSymbol(this.packagePrefix == null ? CL.Package : CL.FindPackage(packagePrefix), this.token));
            }
        }
Esempio n. 8
0
        static public ConsCollection <O> Mapcar <O, I> (object functionSpecifier, System.Collections.Generic.ICollection <I> input)
        {
            if (input == null)
            {
                return(null);
            }
            Function1 <O, I>   function = ResolveFunctionSpecifier <Function1 <O, I> > (functionSpecifier);
            ConsCollection <O> answer   = null;

            foreach (I element in input)
            {
                answer = new ConsCollection <O> (function(element), answer);
            }
            return(CL.Reverse(answer));
        }
Esempio n. 9
0
        static public ConsCollection <T> RemoveDuplicates <T> (System.Collections.Generic.IList <T> list)
        {
            if (list == null)
            {
                return(null);
            }
            ConsCollection <T> answer = null;

            foreach (T element in list)
            {
                if ((answer == null) || !((System.Collections.Generic.IList <T>)answer).Contains(element))
                {
                    answer = new ConsCollection <T> (element, answer);
                }
            }
            return(CL.Reverse(answer));
        }
Esempio n. 10
0
        static public object GetArgStar(object list, ConsCollection <Symbol> keys, object defaultValue)
        {
            if (list == null)
            {
                return(defaultValue);
            }
            Cons firstPair  = (Cons)list;
            Cons secondPair = (Cons)(firstPair.Cdr);

            if (CL.Memq <Symbol> ((Symbol)firstPair.Car, keys) != null)
            {
                return(secondPair.Car);
            }
            else
            {
                return(GetArgStar(secondPair.Cdr, keys, defaultValue));
            }
        }
Esempio n. 11
0
        public override ReaderMacroStep NextStep()
        {
            Cons   head = null;
            object tail = null;

            Readtable currentReadtable = CL.Readtable;

            while (true)
            {
                int  xx;
                char x;
                // Discard whitespace
                do
                {
                    xx = this.context.InputStream.Peek();
                    if (xx == -1)
                    {
                        throw new NotImplementedException();
                    }
                    else
                    {
                        x = (char)xx;
                    }
                }while (currentReadtable.IsWhitespaceSyntax(x) && (this.context.InputStream.Read() != -1));
                if (x == ')')
                {
                    this.context.InputStream.Read();  // discard the close paren
                    return((CL.ReadSuppress == true)
                    ? new FinalReaderMacroStep()
                    : new FinalReaderMacroStep(CL.Reconc(head, tail)));
                }
                //else if (x == '.') {
                //    throw new NotImplementedException ();
                //}
                else
                {
                    object next = CL.Read(this.context.InputStream, true, null, true);  // recursive read
                    if (CL.ReadSuppress != true)
                    {
                        head = CL.Cons(next, head);
                    }
                }
            }
        }
Esempio n. 12
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)));
        }
Esempio n. 13
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)));
        }
Esempio n. 14
0
        public Delegate SymbolFunction(Symbol id)
        {
            ILocation <Delegate> binding;

            if (functions.TryGetValue(id, out binding))
            {
                return(binding.Value);
            }
            if (id.NamesDotnetMethod())
            {
                Delegate gf = (Delegate)CL.EnsureGenericFunction(id, KW.GenericFunctionClass, CLOS.DotnetGenericFunction,
                                                                 KW.Environment, this,
                                                                 KW.StudlyName, id.Name);
                binding = new ValueCell <Delegate> (gf);
                return(binding.Value);
            }
            else
            {
                throw new NotImplementedException();
            }
        }
Esempio n. 15
0
        static Cons MapListToList1(object functionSpecifier, Cons sequence)
        {
            Delegate function = ResolveFunctionSpecifier(functionSpecifier);
            Cons     answer   = null;

            while (sequence != null)
            {
                answer = new Cons(function.DynamicInvoke(sequence.Car), answer);
                object temp = sequence.Cdr;
                if (temp == null)
                {
                    break;
                }
                Cons next = temp as Cons;
                if (next == null)
                {
                    throw new NotImplementedException();
                }
                sequence = next;
            }
            return((Cons)CL.Reverse(answer));
        }
Esempio n. 16
0
        static Cons Evlis(object formlist)
        {
            Cons evaluated = null;

            while (true)
            {
                Cons formpair = formlist as Cons;
                if (formpair != null)
                {
                    evaluated = new Cons(Eval(formpair.Car), evaluated);
                    formlist  = formpair.Cdr;
                }
                else if (formpair == null)
                {
                    return((Cons)CL.Reverse(evaluated));
                }
                else
                {
                    throw new NotImplementedException();
                }
            }
        }
Esempio n. 17
0
        static public object Eval(object form)
        {
            Cons pair = form as Cons;

            if (pair != null)
            {
                object op       = pair.Car;
                object operands = pair.Cdr;
                object sym      = op as Symbol;
                if (sym != null)
                {
                    return(CL.Apply(CL.SymbolFunction(sym), Evlis(operands)));
                }
                else
                {
                    throw new NotImplementedException("Operator not a symbol");
                }
            }
            else
            {
                Symbol identifier = form as Symbol;
                if (identifier != null)
                {
                    return(CL.SymbolValue(form));
                }
                else
                {
                    string literal = form as String;
                    if (literal != null)
                    {
                        return(literal);
                    }
                    else
                    {
                        throw new NotImplementedException("No lambda functions yet");
                    }
                }
            }
        }
Esempio n. 18
0
        static System.Collections.Generic.IList <T> MapListToList1 <I, T> (object functionSpecifier, ConsCollection <I> sequence)
        {
            Delegate           function = ResolveFunctionSpecifier(functionSpecifier);
            ConsCollection <T> answer   = null;

            while (sequence != null)
            {
                answer = new ConsCollection <T> ((T)function.DynamicInvoke(sequence.Car), answer);
                object temp = sequence.Cdr;
                if (temp == null)
                {
                    break;
                }
                ConsCollection <I> next = temp as ConsCollection <I>;
                if (next == null)
                {
                    throw new NotImplementedException();
                }
                sequence = next;
            }
            return(CL.Reverse <T> (answer));
        }
Esempio n. 19
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)));
        }
Esempio n. 20
0
 static public ConsCollection <T> Reverse <T> (System.Collections.Generic.IList <T> list)
 {
     return(CL.Reconc <T> (list, null));
 }
Esempio n. 21
0
 static public object Reverse(object list)
 {
     return(CL.Reconc(list, null));
 }
Esempio n. 22
0
 // Append
 public static object Append(object left, object right)
 {
     return(CL.Reconc(CL.Reverse(left), right));
 }
Esempio n. 23
0
 public static object Cddr(object thing)
 {
     return((thing == null) ? null : CL.Cdr(CL.Cdr(thing)));
 }
Esempio n. 24
0
 public static ConsCollection <T> Append <T> (System.Collections.Generic.IList <T> left, ConsCollection <T> right)
 {
     return(CL.Reconc <T> (CL.Reverse <T> (left), right));
 }
Esempio n. 25
0
 // CDDR
 public static object Cddr(Cons thing)
 {
     return((thing == null) ? null : CL.Cdr(thing.Cdr));
 }
Esempio n. 26
0
 static public Cons Reverse(Cons list)
 {
     return((Cons)CL.Reconc(list, null));
 }