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


C# Cons.Caar方法代码示例

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


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

示例1: ProcessKeyArguments

        private static void ProcessKeyArguments(Cons argumentNameList, Cons argumentList,
                                                Environment localEnvironment)
        {
            // Make sure that all of the defined key arguments are inserted to the local enviroment with their
            // defaults.

            while (argumentNameList != null)
            {
                Symbol argumentName = null;
                object argumentValue = null;


                // We need to get the name of the argument, it can either be just the name or, it can be
                // it's own Cons with the name and an expression for the default value.

                if (argumentNameList.Car().GetType() == typeof(Cons))
                {
                    // It is a Cons, so extract the name and the default value.  Because the default can be
                    // any expression, we need to evaluate the value every time the function is called.

                    argumentName = (Symbol)argumentNameList.Caar();
                    argumentValue = Runtime.Eval(argumentNameList.Cadar(), localEnvironment);
                }
                else
                {
                    argumentName = (Symbol)argumentNameList.Car();
                }


                // Add this variable to the closure's environment, then advance to the next parameter.

                localEnvironment.AssignLocal(argumentName, argumentValue);

                argumentNameList = (Cons)argumentNameList.Cdr();
            }


            // Now that the parameters and their defaults have been added to the environment we can now
            // process the supplied arguments.

            while (argumentList != null)
            {
                // Because these are keyed parameters, the caller needs to specify the name of each
                // parameter.

                if (argumentList.Car().GetType() != typeof(Symbol))
                {
                    throw new LSharpException("Key parameters must be specified by name.");
                }


                // Grab the current parameter and the value associated with it.  Then make sure that this
                // is a keyword.

                Symbol keywordName = (Symbol)argumentList.Car();
                object argumentValue = argumentList.Cadr();

                if (keywordName.Name[0] != ':')
                {
                    throw new LSharpException(keywordName + " is not a valid keyword.");
                }


                // Now that we know they supplied a keyword, create a symbol out of it and make sure that
                // it exists.

                //keywordName = new Symbol(keywordName.Name.Substring(1));
                keywordName = Symbol.FromName(keywordName.Name.Substring(1));

                if (localEnvironment.Contains(keywordName) == false)
                {
                    throw new LSharpException(keywordName + " is not a recognised keyword.");
                }


                // Update the parameter with the value that the user specified and then move onto the next
                // argument in the list.

                localEnvironment.AssignLocal(keywordName, argumentValue);
                argumentList = (Cons)argumentList.Cddr();
            }

        }
开发者ID:westybsa,项目名称:MP.LSharp,代码行数:83,代码来源:Primitives.cs

示例2: ProcessOptionalArguments

        private static void ProcessOptionalArguments(Cons argumentNameList, Cons argumentList,
                                                     Environment localEnvironment)
        {
            // We need to add all the arguments to the closure's environment.

            while (argumentNameList != null)
            {
                Symbol argumentName = null;
                object argumentValue = null;


                // We need to get the name of the argument, it can either be just the name or, it can be
                // it's own Cons with the name and an expression for the default value.

                if (argumentNameList.Car().GetType() == typeof(Cons))
                {
                    // It is a Cons, so extract the name and the default value.

                    argumentName = (Symbol)argumentNameList.Caar();
                    argumentValue = argumentNameList.Cadar();
                }
                else
                {
                    argumentName = (Symbol)argumentNameList.Car();
                }


                // Now, if the caller has specified a value for this argument, get it now.

                if (argumentList != null)
                {
                    argumentValue = argumentList.Car();
                    argumentList = (Cons)argumentList.Cdr();
                }


                // Finally add the parameter to the closure's list and then move onto the next argument.
                // Because the default can be any expression, we need to evaluate the value every time the
                // function is called.

                localEnvironment.AssignLocal(argumentName, Runtime.Eval(argumentValue, localEnvironment));

                argumentNameList = (Cons)argumentNameList.Cdr();
            }


            // Looks like the caller has supplied more parameters than the closure can use.

            if (argumentList != null)
            {
                throw new LSharpException("Too many parameters given.");
            }
        }
开发者ID:westybsa,项目名称:MP.LSharp,代码行数:53,代码来源:Primitives.cs


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