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


C# Cons.Nth方法代码示例

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


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

示例1: DefMethod

		/// <summary>
		/// (defmethod name "arg1 arg2" "(expression1)" "(expression 2)" [...])
		/// Created methods used for DefClass <br />
		/// </summary>
		/// <param name="args"></param>
		/// <param name="e"></param>
		/// <returns></returns>
		public static object DefMethod(Cons args, Environment e)
		{
			string name;
			string[] _args;
			string commands = "";
			name = args.First().ToString();
			_args = args.Second().ToString().Split(new string[] {" "}, StringSplitOptions.None);;
			for (int i = 2; i < args.Length(); i++)
				commands += args.Nth(i) + " ";
			commands = commands.Replace("\\", "\\\\");
			commands = commands.Replace("\"", "\\\"");
			//FIXME: 
			//code = code.Replace("\n", "\\n");
			DefinedMethod ret = new DefinedMethod(commands, name, _args);
			e.AssignLocal(Symbol.FromName(name), ret);
			Console.WriteLine("Assigned '" + ret.Name + "' as a DefinedMethod");
			return ret;
		}
开发者ID:mlnlover11,项目名称:MP.LSharp,代码行数:25,代码来源:SpecialForms.cs

示例2: Nconc

        /// <summary>
        /// (nconc list*)
        /// Returns a list whose elements are the elements of each list in
        /// order. Destructively modifies all but the last list, such that
        /// the cdr of the last cons in each list is the next list.
        /// </summary>
        /// <param name="args"></param>
        /// <param name="environment"></param>
        /// <returns></returns>
        public static Object Nconc(Cons args, Environment environment)
        {
            // With no argument, returns null
            if (args == null)
                return null;

            // With one argument, returns that argument
            if (args.Length() < 2)
                return args.First();

            for (int i = 0; i < args.Length() -1; i ++)
            {
                Cons cons = (Cons)args.Nth(i);
                cons = (Cons)cons.Last();
                cons.Rplacd(args.Nth(i+1));
            }

            return args.First();
        }
开发者ID:westybsa,项目名称:MP.LSharp,代码行数:28,代码来源:Functions.cs

示例3: DefClass

		/// <summary>
		/// Creates a dynamic class
		/// (defclass "classname" "inheritsfrom" [defmethod]) 
		/// e.g. (defclass "class1" "Object" DefinedMethods*)
		/// </summary>
		/// <param name="args"></param>
		/// <param name="environment"></param>
		/// <returns></returns>
		public static Object DefClass(Cons args, Environment environment) 
		{
			string className = args.First().ToString();
			string superClass = args.Second().ToString();
			
			DefinedMethod[] methods = new DefinedMethod[args.Length() - 2];
			for (int i = 2; i < args.Length(); i++) 
			{
				try {
					Symbol toFind = (Symbol) args.Nth(i);
					object foundMethod =  environment.GetValue(toFind);
					methods[i - 2] = (DefinedMethod) foundMethod;
				} catch (Exception e ) {
					Console.WriteLine("DEFCLASS ERROR: " + e.Message + " " + e.StackTrace);
				}
			}
			return ClassBuilder.CreateClass(className, superClass, "", methods);
		}
开发者ID:mlnlover11,项目名称:MP.LSharp,代码行数:26,代码来源:SpecialForms.cs


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