本文整理汇总了C#中LSharp.Cons.Third方法的典型用法代码示例。如果您正苦于以下问题:C# Cons.Third方法的具体用法?C# Cons.Third怎么用?C# Cons.Third使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LSharp.Cons
的用法示例。
在下文中一共展示了Cons.Third方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Try
/// <summary>
/// (try expression catch [finally])
/// The try special form corresponds to the try-catch-finally construct found
/// in C#. If catch is null then there is deemed to be no catch block
/// at all. If an exception occurs, the variable "it" is bound to the Exception
/// object in the local environment.
/// </summary>
/// <param name="args"></param>
/// <param name="environment"></param>
/// <returns></returns>
public static Object Try(Cons args, Environment environment)
{
try
{
return Runtime.Eval(args.First(),environment);
}
catch (Exception e)
{
environment.AssignLocal(Symbol.IT,e);
// If a catch form is specified then evaluate it
if (args.Second() == Symbol.NULL)
throw;
return Runtime.Eval(args.Second(),environment);
}
finally
{
// If a finally form was specified then evaluate it
if (args.Length() > 2)
Runtime.Eval(args.Third(),environment);
}
}
示例2: HandleEvent
/// <summary>
/// (handle-event target eventName handler)
/// Sets up a new event handler for events named eventName on target. The
/// handler is an LSharp closure with two arguments, the sender and the
/// event arguments (defun fn (sender args) (prl "Event Handled")).
/// Experimental.
/// </summary>
/// <param name="args"></param>
/// <param name="environment"></param>
/// <returns></returns>
public static Object HandleEvent(Cons args, Environment environment)
{
return EventAdapter.AddEventHandler(args.First(), (string)args.Second(), (Closure)args.Third());
}
示例3: If
/// <summary>
/// (if test then [else])
/// The if special form corresponds to the if-then-else construct found in
/// most algebraic programming languages. First the form test is evauated,
/// if true then the form then is evaluated.Otherwise, optionally the form
/// else is evaluated.
/// </summary>
/// <param name="args"></param>
/// <param name="environment"></param>
/// <returns></returns>
public static Object If(Cons args, Environment environment)
{
if (Conversions.ObjectToBoolean(Runtime.Eval(args.First(),environment)))
// Evaluate the then part
return Runtime.Eval(args.Second(),environment);
else
if (args.Length() > 2)
// Evaluate the optional else part
return Runtime.Eval(args.Third(),environment);
else
return null;
}
示例4: For
/// <summary>
/// (for initialiser test iterator statement)
/// The for special form corresponds to the for construct found in most algebraic
/// programming languages. The initialiser is executed. The statement is executed
/// while test is true. The iterator is executed at the end of each statement execution.
/// </summary>
/// <param name="args"></param>
/// <param name="environment"></param>
/// <returns></returns>
public static Object For(Cons args, Environment environment)
{
Environment localEnvironment = new Environment(environment);
Runtime.Eval(args.First(),localEnvironment);
object test;
while ((Conversions.ObjectToBoolean(test = Runtime.Eval(args.Second(),localEnvironment))))
{
foreach (object item in (Cons)args.Cdddr())
{
Runtime.Eval(item, localEnvironment);
}
Runtime.Eval(args.Third(),localEnvironment);
}
return test;
}
示例5: 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;
}
示例6: 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;
}
示例7: Try
/// <summary>
/// (try expression catch [finally])
/// </summary>
public static Object Try(Cons args, LSharp.Environment environment)
{
string v = "";//"//(try " + Printer.ConsToString(args) + ")" + NewLine +
string.Format(@"
try
{{
{0}
}}
catch (Exception e)
{{
{1}
}}", Generate(args.First(), environment) ,(args.Second() as Symbol == Symbol.NULL) ?
"throw" :
Generate(args.Second(),environment));
if (args.Length() > 2)
{
v += string.Format(@"
finally
{{
{0}
}}
", Generate(args.Third(),environment));
}
return v;
}