本文整理汇总了C#中LSharp.Cons.Rest方法的典型用法代码示例。如果您正苦于以下问题:C# Cons.Rest方法的具体用法?C# Cons.Rest怎么用?C# Cons.Rest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LSharp.Cons
的用法示例。
在下文中一共展示了Cons.Rest方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Eq
public static bool Eq(Cons args)
{
object last = args.First();
foreach (object item in (Cons)args.Rest())
{
if (!(object.ReferenceEquals(last,item)))
return false;
last = item;
}
return true;
}
示例2: Append
// TODO
public static Object Append(Cons args, Environment environment)
{
if (args.Rest() == null)
{
return args.First();
}
else
{
Cons result;
if (args.First() == null)
{
result = (Cons)Append((Cons)args.Rest(), environment);
}
else
{
result = ((Cons)args.First()).CopyList();
((Cons)result.Last()).Rplacd(Append((Cons)args.Rest(), environment));
}
return result;
}
}
示例3: New
/// <summary>
/// (new class) Creates a new object, an instance of type class
/// </summary>
/// <param name="args"></param>
/// <param name="environment"></param>
/// <returns></returns>
public static Object New(Cons args, Environment environment)
{
Type type = TypeCache.Instance().FindType(args.First().ToString());
return Runtime.MakeInstance(type,args.Rest());
}
示例4: Mod
public static Object Mod(Cons args, Environment environment)
{
Type type = args.First().GetType();
Double result = Convert.ToDouble(args.First());
foreach (object item in (Cons)args.Rest())
{
if (item is Double)
type = item.GetType();
result %= Convert.ToDouble(item);
}
return Convert.ChangeType(result, type);
}
示例5: MacroExpand
public static Object MacroExpand(Cons args, Environment environment)
{
Macro macro = (Macro)args.First();
Cons arguments = (Cons)args.Rest();
return macro.Expand(arguments);
}
示例6: LogXor
/// <summary>
/// (^ expression*)
/// Performs a bitwise logical exclusive or operation on its arguments
/// </summary>
/// <param name="args"></param>
/// <param name="environment"></param>
/// <returns></returns>
public static Object LogXor(Cons args, Environment environment)
{
Type type = args.First().GetType();
object result = args.First();
foreach (Object item in (Cons)args.Rest())
{
// The integral types dont define operator overload methods
// for performace reasons, so we have to implement this
// operator on each integral type
if (type == typeof(sbyte))
result = (sbyte)result ^ (sbyte)(item);
else if (type == typeof(byte))
result = (byte)result ^ (byte)(item);
else if (type == typeof(char))
result = (char)result ^ (char)(item);
else if (type == typeof(short))
result = (short)result ^ (short)(item);
else if (type == typeof(ushort))
result = (ushort)result ^ (ushort)(item);
else if (type == typeof(int))
result = (int)result ^ (int)(item);
else if (type == typeof(uint))
result = (uint)result ^ (uint)(item);
else if (type == typeof(long))
result = (long)result ^ (long)(item);
else if (type == typeof(ulong))
result = (ulong)result ^ (ulong)(item);
else
return Runtime.Call("op_ExclusiveOr",args);
}
return Convert.ChangeType(result,type);
}
示例7: LessThanEqual
/// <summary>
/// (<= object1 object2 object*) Less than or equal
/// </summary>
/// <param name="args"></param>
/// <param name="environment"></param>
/// <returns></returns>
public static Object LessThanEqual(Cons args, Environment environment)
{
Double last = Convert.ToDouble(args.First());
foreach (object item in (Cons)args.Rest())
{
Double current = Convert.ToDouble(item);
if (!(last <= current))
return false;
last = current;
}
return true;
}
示例8: Cons
/// <summary>
/// Creates a fresh cons, the car of which is object-1 and the cdr of which is object-2.
/// </summary>
/// <param name="args"></param>
/// <param name="environment"></param>
/// <returns></returns>
public static Object Cons(Cons args, Environment environment)
{
if (args.Length() == 1)
return args.First();
if (args.Length() == 2)
return new Cons(args.First(),Cons((Cons)args.Rest(), environment));
throw new LSharpException("Too many arguments given to cons");
}
示例9: Call
/// <summary>
/// Calls a .NET method.
/// The first argument is the object to which the method is attached.
/// Passes the rest of the arguments to the appropriate constructor
/// </summary>
/// <param name="method"></param>
/// <param name="arguments"></param>
/// <returns></returns>
public static object Call(String method, Cons arguments)
{
BindingFlags bindingFlags = BindingFlags.IgnoreCase
| BindingFlags.Public
| BindingFlags.NonPublic;
// Is it a method on a static type or an object instance ?
Type type;
if (arguments.First().GetType() == typeof(LSharp.Symbol))
{
bindingFlags = bindingFlags | BindingFlags.Static | BindingFlags.FlattenHierarchy;
// Find the type object from its name
type = TypeCache.Instance().FindType(arguments.First().ToString());
}
else
{
bindingFlags = bindingFlags | BindingFlags.Instance;
type = arguments.First().GetType();
}
Type[] types = new Type[arguments.Length() -1];
object[] parameters = new object[arguments.Length() -1];
int loop = 0;
if (arguments.Rest() != null)
foreach (object argument in (Cons)arguments.Rest())
{
types[loop] = argument.GetType();
parameters[loop] = argument;
loop++;
}
// Start by looking for a method call
MethodInfo m = type.GetMethod(method.ToString(),
bindingFlags | BindingFlags.InvokeMethod
,null,types,null);
if (m != null)
return m.Invoke(arguments.First(),parameters);
// Now loook for a property get
PropertyInfo p = type.GetProperty(method.ToString(),bindingFlags | BindingFlags.GetProperty,
null,null, types,null);
if (p != null)
return p.GetGetMethod().Invoke(arguments.First(),parameters);
// Now look for a field get
FieldInfo f = type.GetField(method.ToString(),bindingFlags | BindingFlags.GetField);
if (f != null)
return f.GetValue(arguments.First());
// FIXME: or an event ?
EventInfo e = type.GetEvent(method.ToString(), bindingFlags); // | BindingFlags.Event)
if (e != null) // attempt to call the click event
return e.GetRaiseMethod().Invoke(arguments.First(), parameters);
throw new LSharpException(string.Format("Call: No such method, property, field, or event '{0}' on '{1}'", method.ToString(),type));
}
示例10: Call
/// <summary>
/// (call method object argument*)
/// Calls a .NET method on a given object with given arguments.
/// This is useful if the method name clashes with a variable which is already
/// bound in the current L Sharp lexical environment.
/// </summary>
/// <param name="args"></param>
/// <param name="environment"></param>
/// <returns></returns>
public static Object Call(Cons args, Environment environment)
{
return Runtime.Call(args.Car().ToString(),
(Cons)Runtime.EvalList(args.Rest(),environment));
}
示例11: While
/// <summary>
/// (while test expression*)
/// The while special form corresponds to the while construct found
/// in most algebraic programming languages. First test is evauated,
/// if true then expression* is evaluated. The process continues until
/// the evaluation of test is false.
/// </summary>
/// <param name="args"></param>
/// <param name="environment"></param>
/// <returns></returns>
public static Object While(Cons args, Environment environment)
{
object test;
while ((Conversions.ObjectToBoolean(test = Runtime.Eval(args.First(),environment))))
{
foreach (object item in (Cons)args.Rest())
{
Runtime.Eval(item, environment);
}
}
return test;
}
示例12: Trace
/// <summary>
/// (trace filename expression*)
/// Traces an evaluation of expression* (as if in an implicit do),
/// documenting all call and return steps; writes the output as an
/// XML file in filename.
/// </summary>
/// <param name="args"></param>
/// <param name="environment"></param>
/// <returns></returns>
public static Object Trace(Cons args, Environment environment)
{
string filename = (String)Runtime.Eval(args.First(),environment);
try
{
Runtime.Profiler = new XmlTracer(filename);
object result = null;;
foreach (object item in (Cons)args.Rest())
{
result = Runtime.Eval(item, environment);
}
return result;
}
catch (Exception e)
{
throw;
}
finally
{
Runtime.Profiler.Close();
Runtime.Profiler = new DefaultProfiler();
}
}
示例13: GenerateCons
public static string GenerateCons(Cons args, LSharp.Environment environment)
{
// ananlysi cons
if (args == null)
{
return @"//retval = null; // dont null mite need retval
";
}
else
{
Symbol sym = args.Car() as Symbol;
object e = Runtime.Eval(sym, environment);
if (e is Function)
{
Function f = e as Function;
string v = "{" + NewLine;
Cons rest = args.Rest() as Cons;
v += GenerateFuncCall(f.Method.DeclaringType.ToString(), f.Method.Name, rest, environment);
return v + "}" + NewLine;
}
else if (e is SpecialForm)
{
SpecialForm f = e as SpecialForm;
Cons rest = args.Rest() as Cons;
string r = Printer.ConsToString(rest);
string lFName = f.Method.Name.ToLower();
if (lFName == "while")
return While(rest, environment) as string;
if (lFName == "for")
return For(rest, environment) as string;
if (lFName == "and")
return And(rest, environment) as string;
if (lFName == "call")
return Call(rest, environment) as string;
if (lFName == "cond")
return Cond(rest, environment) as string;
if (lFName == "do")
return Do(rest, environment) as string;
if (lFName == "foreach")
return ForEach(rest, environment) as string;
if (lFName == "if")
return If(rest, environment) as string;
if (lFName == "let")
return Let(rest, environment) as string;
if (lFName == "or")
return Or(rest, environment) as string;
if (lFName == "quote")
return Quote(rest, environment) as string;
if (lFName == "setq")
return Setq(rest, environment) as string;
if (lFName == "the")
return The(rest, environment) as string;
if (lFName == "to")
return To(rest, environment) as string;
if (lFName == "try")
return Try(rest, environment) as string;
if (lFName == "when")
return When(rest, environment) as string;
if (lFName == "with")
return With(rest, environment) as string;
return Runtime.EvalString("(" + f.Method.Name + " " + r + ")", environment) as string;
}
else if (e is Macro)
{
Macro m = e as Macro;
Cons rest = args.Rest() as Cons;
Cons em = m.Expand(rest) as Cons;
return Generate(em, environment);
}
else if (e is Closure)
{
extracode += Closure(new Cons(sym), environment) as string;
string v = "{" + NewLine;
Cons rest = args.Rest() as Cons;
v += GenerateFuncCall(null, environment.GetValue(sym) as string, rest, environment);
return v + "}" + NewLine;
}
else if (currsymbols.ContainsKey(sym))
{
string v = "{" + NewLine;
Cons rest = args.Rest() as Cons;
v += GenerateFuncCall(null, environment.GetValue(sym) as string, rest, environment);
return v + "}" + NewLine;
}
else
{
// not good, lets not support this for now: .NET method call
try
{
//.........这里部分代码省略.........
示例14: While
/// <summary>
/// (while test expression*)
/// </summary>
public static Object While(Cons args, LSharp.Environment environment)
{
string v = "";//"//(while " + Printer.ConsToString(args) + ")" + NewLine;
v += Generate(args.First(),environment);
v += @"
while (LSharp.Conversions.ObjectToBoolean(retval))
{
";
foreach (object item in (Cons)args.Rest())
{
v += Generate(item, environment);
}
v += Generate(args.First(),environment);
v += "}" + NewLine;
return v;
}