当前位置: 首页>>代码示例>>C#>>正文


C# ScheminPair.ListCdr方法代码示例

本文整理汇总了C#中ScheminPair.ListCdr方法的典型用法代码示例。如果您正苦于以下问题:C# ScheminPair.ListCdr方法的具体用法?C# ScheminPair.ListCdr怎么用?C# ScheminPair.ListCdr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ScheminPair的用法示例。


在下文中一共展示了ScheminPair.ListCdr方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Execute

        public override IScheminType Execute(Environment env, Evaluator eval, ScheminPair args)
        {
            IScheminType key = args.Car;
            ScheminPair checks = args.ListCdr();

            foreach (IScheminType type in checks)
            {
                ScheminPair pairCase = (ScheminPair) type;
                IScheminType group = pairCase.Car;
                IScheminType result = pairCase.ListCdr().Car;

                if ((group as ScheminAtom) != null)
                {
                    ScheminAtom atomClause = (ScheminAtom) group;
                    if (atomClause.Name == "else")
                    {
                        return result;
                    }
                    else
                    {
                        throw new Exception("atom besides 'else' found in case statement");
                    }
                }

                ScheminPair pairGroup = (ScheminPair) group;
                foreach (IScheminType checkType in pairGroup)
                {
                    if (key.Equivalent(checkType))
                        return result;
                }
            }

            return new ScheminPair();
        }
开发者ID:imphasing,项目名称:schemin,代码行数:34,代码来源:Case.cs

示例2: Execute

        public override IScheminType Execute(Environment env, Evaluator eval, ScheminPair args)
        {
            ScheminVector vec = (ScheminVector) args.Car;
            ScheminInteger pos = (ScheminInteger) args.ListCdr().Car;

            int pos_int = (int) pos.IntegerValue();
            return vec.List[pos_int];
        }
开发者ID:imphasing,项目名称:schemin,代码行数:8,代码来源:VectorRef.cs

示例3: ScheminLambda

        public ScheminLambda(ScheminPair definition, Environment closure)
        {
            this.Arguments = definition.Car;

            ScheminPair def = definition.ListCdr();
            def = def.Cons(new ScheminPrimitive("begin"));
            this.Definition = def;

            this.Closure = closure;
        }
开发者ID:imphasing,项目名称:schemin,代码行数:10,代码来源:ScheminLambda.cs

示例4: Execute

        public override IScheminType Execute(Environment env, Evaluator eval, ScheminPair args)
        {
            ScheminVector vec = (ScheminVector) args.Car;
            IScheminType fill = args.ListCdr().Car;

            for (int i = 0; i < vec.List.Count; i++)
            {
                vec.List[i] = fill;
            }

            return new ScheminPair();
        }
开发者ID:imphasing,项目名称:schemin,代码行数:12,代码来源:VectorFill.cs

示例5: Execute

        public override IScheminType Execute(Environment env, Evaluator eval, ScheminPair args)
        {
            IScheminType function = args.Car;
            ScheminPair argList = args.ListCdr();
            ScheminPair toApply = (ScheminPair) args.ListCdr().Last();

            ScheminPair list = new ScheminPair();
            foreach (IScheminType type in toApply)
            {
                list = list.Append(type);
            }

            foreach (IScheminType type in argList)
            {
                if (type != toApply)
                    list = list.Cons(type);
            }

            list = list.Cons(function);

            return list;
        }
开发者ID:imphasing,项目名称:schemin,代码行数:22,代码来源:Apply.cs

示例6: Execute

        public override IScheminType Execute(Environment env, Evaluator eval, ScheminPair args)
        {
            bool dec = false;
            var first = (IScheminNumeric) args.Car;
            IScheminNumeric result = null;

            foreach (IScheminType type in args)
            {
                if ((type as ScheminDecimal) != null)
                {
                    dec = true;
                    result = new ScheminDecimal(first.DecimalValue());
                }
            }

            if (!dec)
            {
                result = new ScheminInteger(first.IntegerValue());
            }

            if (args.Length < 2)
            {
                if (dec)
                {
                    return new ScheminDecimal(first.DecimalValue() * -1);
                }
                else
                {
                    return new ScheminInteger(first.IntegerValue() * -1);
                }
            }

            foreach (IScheminType type in args.ListCdr())
            {
                if ((type as IScheminNumeric) != null)
                {
                    var temp = (IScheminNumeric) type;
                    if (dec)
                    {
                        result = new ScheminDecimal(result.DecimalValue() - temp.DecimalValue());
                    }
                    else
                    {
                        result = new ScheminInteger(result.IntegerValue() - temp.IntegerValue());
                    }
                }
            }

            return (IScheminType) result;
        }
开发者ID:imphasing,项目名称:schemin,代码行数:50,代码来源:Subtract.cs

示例7: CheckArguments

        public override void CheckArguments(ScheminPair args)
        {
            IScheminType first = args.Car;
            IScheminType second = args.ListCdr().Car;

            if (args.Length != 2)
            {
                throw new BadArgumentsException("expected 2 arguments");
            }

            if ((first as IScheminNumeric) == null || (second as IScheminNumeric) == null)
            {
                throw new BadArgumentsException("arguments must be numeric");
            }

            return;
        }
开发者ID:imphasing,项目名称:schemin,代码行数:17,代码来源:NumericalEqual.cs

示例8: CheckArguments

        public override void CheckArguments(ScheminPair args)
        {
            IScheminType first = args.Car;
            IScheminType second = args.ListCdr().Car;

            if (args.Length > 2 || args.Length < 1)
            {
                throw new BadArgumentsException("expected 1 or 2 arguments");
            }

            if ((first as ScheminInteger) == null)
            {
                throw new BadArgumentsException("first argument must be an integer");
            }

            return;
        }
开发者ID:imphasing,项目名称:schemin,代码行数:17,代码来源:MakeVector.cs

示例9: CheckArguments

        public override void CheckArguments(ScheminPair args)
        {
            IScheminType first = args.Car;
            IScheminType last = args.ListCdr().Last();

            if ((first as ScheminPrimitive) == null && (first as ScheminLambda) == null
                    && (first as ScheminContinuation) == null && (first as ScheminRewriter) == null)
            {
                throw new BadArgumentsException("first argument must be a procedure");
            }

            if ((last as ScheminPair) == null)
            {
                throw new BadArgumentsException("last argument must be a list");
            }

            return;
        }
开发者ID:imphasing,项目名称:schemin,代码行数:18,代码来源:Apply.cs

示例10: Execute

        public override IScheminType Execute(Environment env, Evaluator eval, ScheminPair args)
        {
            ScheminInteger len = (ScheminInteger) args.Car;
            IScheminType init = args.ListCdr().Car;

            ScheminVector vec = new ScheminVector();
            if (args.Length == 1)
            {
                ScheminPair empty = new ScheminPair();
                for (int i = 0; i < len.IntegerValue(); i++)
                {
                    vec.List.Add(empty);
                }
            }
            else
            {
                for (int i = 0; i < len.IntegerValue(); i++)
                {
                    vec.List.Add(init);
                }
            }

            return vec;
        }
开发者ID:imphasing,项目名称:schemin,代码行数:24,代码来源:MakeVector.cs

示例11: Execute

        public override IScheminType Execute(Environment env, Evaluator eval, ScheminPair args)
        {
            bool isNamed = false;
            if ((args.Car as ScheminAtom) != null)
            {
                isNamed = true;
            }

            ScheminPair bindings;
            ScheminPair expression;

            if (!isNamed)
            {
                expression = args.ListCdr();
                bindings = (ScheminPair)args.Car;
            }
            else
            {
                expression = args.ListCdr().ListCdr();
                bindings = (ScheminPair)args.ElementAt(1);
            }

            ScheminPair letArgs = new ScheminPair();
            ScheminPair argExps = new ScheminPair();

            foreach (ScheminPair bindingPair in bindings)
            {
                letArgs = letArgs.Append(bindingPair.Car);
                argExps = argExps.Append(bindingPair.ElementAt(1));
            }

            ScheminPair lambdaDef = new ScheminPair(letArgs);

            foreach (IScheminType type in expression)
            {
                lambdaDef = lambdaDef.Append(type);
            }

            Environment closure = env;
            if (isNamed)
            {
                closure = new Environment();
                closure.parent = env;
            }

            ScheminLambda lam = new ScheminLambda(lambdaDef, closure);

            if (isNamed)
            {
                ScheminAtom name = (ScheminAtom)args.Car;
                closure.AddBinding(name, lam);
            }

            ScheminPair toEvaluate = new ScheminPair(lam);

            foreach (IScheminType arg in argExps)
            {
                toEvaluate = toEvaluate.Append(arg);
            }

            return toEvaluate;
        }
开发者ID:imphasing,项目名称:schemin,代码行数:62,代码来源:Let.cs

示例12: Execute

        public override IScheminType Execute(Environment env, Evaluator eval, ScheminPair args)
        {
            bool deffun = false;

            if ((args.Car as ScheminPair) != null)
            {
                deffun = true;
            }

            if (!deffun)
            {
                ScheminAtom symbol = (ScheminAtom) args.ElementAt(0);
                IScheminType definition = args.ElementAt(1);

                if (env.bindings.ContainsKey(symbol.Name))
                {
                    env.RemoveBinding(symbol);
                    env.AddBinding(symbol, definition);
                }
                else
                {
                    env.AddBinding(symbol, definition);
                }

                return new ScheminPair();
            }
            else
            {
                ScheminPair arguments = (ScheminPair) args.Car;
                ScheminPair expression = args.ListCdr();

                ScheminAtom name = (ScheminAtom) arguments.Car;
                IScheminType lamParams = arguments.Cdr;

                if (lamParams == null)
                    lamParams = new ScheminPair();
                ScheminPair lamArgs = new ScheminPair(lamParams, expression);

                ScheminLambda lam = new ScheminLambda(lamArgs, env);

                if (env.bindings.ContainsKey(name.Name))
                {
                    env.RemoveBinding(name);
                    env.AddBinding(name, lam);
                }
                else
                {
                    env.AddBinding(name, lam);
                }

                return new ScheminPair();
            }
        }
开发者ID:imphasing,项目名称:schemin,代码行数:53,代码来源:Define.cs


注:本文中的ScheminPair.ListCdr方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。