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


C# Cons.Second方法代码示例

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


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

示例1: Call

    /// <summary>
    /// (call method object argument*)
    /// </summary>
    public static Object Call(Cons args, LSharp.Environment environment)
    {
        string v = //"//(call " + Printer.ConsToString(args) + ")" + NewLine +
            "{" + NewLine;

        ArrayList argtypes = new ArrayList();
        ArrayList argz = new ArrayList();

        if (args.Length() > 2)
        {
            foreach (object arg in (args.Cddr() as Cons))
            {
                if (Primitives.IsAtom(arg))
                {
                    argz.Add(Printer.WriteToString(arg));
                }
                else
                {
                    string argn = MakeUnique("arg");
                    string sv = Generate(arg, environment);
                    sv += string.Format(@"{0} {1} = ({0}) retval;
", typeof(object) , argn);

                    argz.Add(argn);

                    v += sv;
                }
                argtypes.Add(typeof(object));
            }
        }

        string typemethname = args.Car().ToString();

        string methname = typemethname;
        string typename = string.Empty;
        Type type = typeof(object);

        int i = methname.LastIndexOf(".");
        
        if (i >= 0)
        {
            methname = methname.Substring(i + 1);
            typename = typemethname.Substring(0, i);
            type = TypeCache.FindType(typename);
        }
        MethodInfo mi = null;
        
        mi = type.GetMethod(methname, BindingFlags.IgnoreCase
                            | BindingFlags.Public | BindingFlags.Instance, binder, argtypes.ToArray(typeof(Type)) as Type[], null);

        string objn = string.Empty;

        if (mi == null)
        {
            type = TypeCache.FindType(args.Second().ToString());
            mi = type.GetMethod(methname, BindingFlags.IgnoreCase
                                | BindingFlags.Public | BindingFlags.Static, binder, argtypes.ToArray(typeof(Type)) as Type[], null);

            if (mi == null)
            {
                // use reflection
                v += Generate(args.Second(), environment);
                v += string.Format(@"retval = retval.GetType().InvokeMember(""{0}"",
BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance, null, retval,
new object[]{{", methname) +
                    string.Join(", ", argz.ToArray(typeof(string)) as string[]) + @"});
}
";
                return v;
            }
            else
            {
                objn = type.ToString();
            }
        }
        else
        {
            objn = MakeUnique("obj");
            v += Generate(args.Second(), environment);
            v += string.Format(@"{0} {1} = ({0}) retval;
", type, objn);
        }

        v += "retval = " + (mi.ReturnType == typeof(void) ? @"null;
" : "") + objn + "." + mi.Name + "(" +
            string.Join(", ", argz.ToArray(typeof(string)) as string[]);
        
        return v + @");
}
";
    }
开发者ID:mlnlover11,项目名称:MP.LSharp,代码行数:94,代码来源:NewCompiler.cs

示例2: Is

        /// <summary>
        /// (is type expression)
        /// Used to check whether the run-time type of an object is
        /// compatible with a given type.
        /// </summary>
        /// <param name="args"></param>
        /// <param name="environment"></param>
        /// <returns></returns>
        public static Object Is(Cons args, Environment environment)
        {
            object obj = args.Second();

            TypeCache typeCache = TypeCache.Instance();
            string typeName = args.First().ToString();
            Type type = typeCache.FindType(typeName);

            object result =  (((Type)type).IsInstanceOfType (obj));

            return result;

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

示例3: Apply

 /// <summary>
 /// (apply function list)
 /// Applies function to a list of arguments. function may be a built-in lsharp function,
 /// a closure defined by fn a macro defined by macro or the name of a method in the
 /// .NET framework.
 /// </summary>
 /// <param name="args"></param>
 /// <param name="environment"></param>
 /// <returns></returns>
 public static Object Apply(Cons args, Environment environment)
 {
     return Runtime.Apply(args.First(), args.Second(),environment);
 }
开发者ID:westybsa,项目名称:MP.LSharp,代码行数:13,代码来源:Functions.cs

示例4: Assoc

        /// <summary>
        /// (assoc item alist)
        /// return the first cons in alist whose car is equal to item,
        /// or nil if no such cons is found.
        /// </summary>
        /// <param name="args"></param>
        /// <param name="environment"></param>
        /// <returns></returns>
        public static Object Assoc(Cons args, Environment environment)
        {
            object item = args.First();
            Cons list = (Cons) args.Second();

            foreach (Cons c in list)
            {
                if (c.Car().Equals (item))
                    return c;
            }
            return null;
            
        }
开发者ID:westybsa,项目名称:MP.LSharp,代码行数:21,代码来源:Functions.cs

示例5: Coerce

        //converts args[0] to type of args[1]
        public static object Coerce(Cons args, Environment e)
        {
            object o = args.First();
            object t = args.Second();
            Type type;

            if (t is String)
                type =(Type) TypeOf(new Cons(t), e);
            else
                type = (Type)t;

            return Convert.ChangeType(o, type, System.Globalization.CultureInfo.InvariantCulture);
        }
开发者ID:westybsa,项目名称:MP.LSharp,代码行数:14,代码来源:Functions.cs

示例6: To

		/// <summary>
		/// (to variable limit expression)
		/// Starting at 0, assigns variable to succesive integers upto and 
		/// including limit. Executes expression on each iteration. 
		/// </summary>
		/// <param name="args"></param>
		/// <param name="environment"></param>
		/// <returns></returns>
		public static Object To(Cons args, Environment environment) 
		{
			Environment localEnvironment = new Environment(environment);
			localEnvironment.AssignLocal((Symbol) args.First(), 0);
			int endStop = int.Parse(Runtime.Eval(args.Second(),localEnvironment).ToString());
			while ((int)localEnvironment.GetValue((Symbol) args.First()) < endStop)
			{
				foreach (object item in (Cons)args.Cddr()) 
				{
					Runtime.Eval(item, localEnvironment);
				}
				localEnvironment.AssignLocal((Symbol) args.First(), ((int)Runtime.Eval(args.First(), localEnvironment)) + 1);
				
			}
			return null;
		}
开发者ID:mlnlover11,项目名称:MP.LSharp,代码行数:24,代码来源:SpecialForms.cs

示例7: Compile

		/// <summary>
		/// (compile expression filename)
		/// This compiles to "expression" to "filename"
		/// </summary>
		/// <param name="args"></param>
		/// <param name="environment"></param>
		/// <returns></returns>
		public static Object Compile(Cons args, Environment environment) 
		{
			return Compiler.Compile(args.First().ToString(), args.Second().ToString(), Compiler.OutputType.Exe);
		}
开发者ID:mlnlover11,项目名称:MP.LSharp,代码行数:11,代码来源:SpecialForms.cs

示例8: The

 /// <summary>
 /// (the type value)
 /// </summary>
 public static Object The(Cons args, LSharp.Environment environment)
 {
     string v = "";// "//(the " + Printer.ConsToString(args) + ")" + NewLine;
     Type o = TypeCache.FindType(args.First().ToString());
     v += Generate(args.Second(),environment);
     return v + string.Format("retval = LSharp.Conversions.The(typeof({0}), retval);", o) + NewLine;
 }
开发者ID:mlnlover11,项目名称:MP.LSharp,代码行数:10,代码来源:NewCompiler.cs

示例9: To

    /// <summary>
    /// (to variable limit expression)
    /// </summary>
    public static Object To(Cons args, LSharp.Environment environment)
    {
        string v = //"//(to " + Printer.ConsToString(args) + ")" + NewLine +
            "{" + NewLine;
        LSharp.Environment localEnvironment = new LSharp.Environment(environment);

        v += GenerateAssignLocal(args.First() as Symbol, 0, localEnvironment);
        v += Generate(args.Second(),environment);
        string lbl = MakeUnique("endstop");
        v += string.Format(@"
int {1} = (int)retval;
while ({0} < {1})
{{
", localEnvironment.GetValue(args.First() as Symbol), lbl);

        foreach (object item in (Cons)args.Cddr())
        {
            v += Generate(item, localEnvironment);
        }

        v += localEnvironment.GetValue(args.First() as Symbol) + "++;";
        
        v += "}" + NewLine;
        v += string.Format(@"
retval = null;
");
        return v + "}" + NewLine;
    }
开发者ID:mlnlover11,项目名称:MP.LSharp,代码行数:31,代码来源:NewCompiler.cs

示例10: Let

    /// <summary>
    /// (let symbol value expression*)
    /// </summary>
    public static Object Let(Cons args, LSharp.Environment environment)
    {
        string v = //"//(let " + Printer.ConsToString(args) + ")" + NewLine +
            "{"  + NewLine;
        LSharp.Environment localEnvironment = new LSharp.Environment(environment);
        v += GenerateAssignLocal((Symbol) args.First(), Generate(args.Second(),environment), localEnvironment);
        
        foreach (object item in (Cons)args.Cddr())
        {
            v += Generate(item, localEnvironment);
        }

        return v + "}" + NewLine;
    }
开发者ID:mlnlover11,项目名称:MP.LSharp,代码行数:17,代码来源:NewCompiler.cs

示例11: Setq

    /// <summary>
    /// (= { symbol value}*)
    /// </summary>
    public static Object Setq(Cons args, LSharp.Environment environment)
    {
        string v = "";//"//(setq " + Printer.ConsToString(args) + ")" + NewLine;

        while (args != null)
        {
            Symbol s = (Symbol)args.First();
            Cons sec = args.Second() as Cons;
            if (sec != null)
            {
                Symbol ss = sec.First() as Symbol;
                if (ss == Symbol.FromName("fn"))
                {
                    Closure c =  Runtime.Eval(sec, environment) as Closure;
                    environment.Assign(s, c);
                    extracode += Closure( new Cons(s), environment);
                    args = (Cons)args.Cddr();
                    continue;
                }
                if (ss == Symbol.FromName("macro"))
                {
                    Macro m =  Runtime.Eval(sec, environment) as Macro;
                    environment.Assign(s, m);
                    args = (Cons)args.Cddr();
                    continue;
                }
            }
            v += GenerateAssign(s,Generate(args.Second(),environment), environment);
            args = (Cons)args.Cddr();
        }

        return v;
    }
开发者ID:mlnlover11,项目名称:MP.LSharp,代码行数:36,代码来源:NewCompiler.cs

示例12: If

    /// <summary>
    /// (if test then [else])
    /// </summary>
    public static Object If(Cons args, LSharp.Environment environment)
    {
        string v = //"//(if " + Printer.ConsToString(args) + ")" + NewLine +
            Generate(args.First(),environment) +
            string.Format(@"
if (LSharp.Conversions.ObjectToBoolean(retval))
{{  // Evaluate the then part
  {0}
}}
", Generate(args.Second(),environment));

        if (args.Length() > 2)
        {
            // Evaluate the optional else part
            v += string.Format(@"
else
{{
  {0}
}}
", Generate(args.Third(),environment));
        }

        return v;
    }
开发者ID:mlnlover11,项目名称:MP.LSharp,代码行数:27,代码来源:NewCompiler.cs

示例13: ForEach

    /// <summary>
    /// (each symbol IEnumerable expression)
    /// </summary>
    public static Object ForEach(Cons args, LSharp.Environment environment)
    {
        //string v = "//(each " + Printer.ConsToString(args) + ")" + NewLine;
        string v = "";
        LSharp.Environment localEnvironment = new LSharp.Environment(environment);
        Symbol variable = (Symbol) args.First();
        
        string vn = localEnvironment.AssignLocal(variable, MakeUnique(variable.Name)) as string;
        
        v += Generate(args.Second(),environment) +
            string.Format(@"
foreach (object {0} in (System.Collections.IEnumerable)retval)
{{", vn);
        
        foreach (object item in (Cons)args.Cddr())
        {
            v += Generate(item, localEnvironment);
        }

        v += "}" + NewLine;

        return v;
    }
开发者ID:mlnlover11,项目名称:MP.LSharp,代码行数:26,代码来源:NewCompiler.cs

示例14: For

    /// <summary>
    /// (for initialiser test iterator statement)
    /// </summary>
    public static Object For(Cons args, LSharp.Environment environment)
    {
        //string v = "//(for " + Printer.ConsToString(args) + ")" + NewLine + "{" + NewLine;
        string v = "{" + NewLine;
        LSharp.Environment localEnvironment = new LSharp.Environment(environment);
        v += Generate(args.First(),localEnvironment);
        v += Generate(args.Second(),localEnvironment);
        v += @"while ((Conversions.ObjectToBoolean(retval))
{
";
        foreach (object item in (Cons)args.Cdddr())
        {
            v += Generate(item, localEnvironment);
        }

        v += Generate(args.Third(),localEnvironment);

        v += Generate(args.Second(),localEnvironment);

        v += @"}
";
        return v + "}" + NewLine;
    }
开发者ID:mlnlover11,项目名称:MP.LSharp,代码行数:26,代码来源:NewCompiler.cs

示例15: Spawn

 /// <summary>
 /// (spawn expression) is like eval except that the expression
 /// is evaluated on a new thread. Returns immediately with
 /// the new thread object, but execution of expressions
 /// continues synchronously. Experimental.
 /// </summary>
 /// <param name="args"></param>
 /// <param name="environment"></param>
 /// <returns></returns>
 public static Object Spawn(Cons args, Environment environment)
 {
     if (args.Length() == 1)
         return ThreadAdapter.Fork(args.First(), environment, System.Threading.ApartmentState.MTA);
     else if (args.Length() == 2)
         return ThreadAdapter.Fork(args.First(), environment, 
             (System.Threading.ApartmentState) Runtime.Eval(args.Second(), environment));
     else
         throw new LSharpException("Incorrect arguments given to spawn");
 }
开发者ID:mlnlover11,项目名称:MP.LSharp,代码行数:19,代码来源:SpecialForms.cs


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