本文整理汇总了C#中LSharp.Cons.First方法的典型用法代码示例。如果您正苦于以下问题:C# Cons.First方法的具体用法?C# Cons.First怎么用?C# Cons.First使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LSharp.Cons
的用法示例。
在下文中一共展示了Cons.First方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GuiInspect
/// <summary>
/// (gui-inspect OBJECT)
/// shows a Form with data on the item OBJECT
/// </summary>
/// <param name="args"></param>
/// <param name="environment"></param>
/// <returns></returns>
public static object GuiInspect(Cons args, Environment environment)
{
// TODO : Fix
//string sname = (string) Functions.SymbolName(new Cons(args.First()), environment);
InspectorForm i = new InspectorForm(args.Car(), environment);
i.ShowDialog();
return args.First();
}
示例2: 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;
}
示例3: 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;
}
}
示例4: Add
/// <summary>
/// (add object*)
/// Returns the sum of all the specified objects.
/// Each object must be a numerical type such as System.In32 or System.Double.
/// </summary>
/// <param name="args"></param>
/// <param name="environment"></param>
/// <returns></returns>
public static Object Add(Cons args, Environment environment)
{
Type type = args.First().GetType();
Double result = 0;
foreach (Object item in args)
{
if (item is Double)
type = item.GetType();
result += Convert.ToDouble(item);
}
return Convert.ChangeType(result,type);
}
示例5: 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;
}
示例6: 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());
}
示例7: Inspect
/// <summary>
/// (inspect object) Returns a description of the specified object, using reflection.
/// Useful for debugging.
/// </summary>
/// <param name="args"></param>
/// <param name="environment"></param>
/// <returns></returns>
public static Object Inspect(Cons args, Environment environment)
{
object o = args.First();
string s = Inspector.Inspect(o);
Console.WriteLine(s);
return null;
}
示例8: SymbolName
/// <summary>
/// (symbol-name symbol) Returns the name of a symbol as a string
/// </summary>
/// <param name="args"></param>
/// <param name="environment"></param>
/// <returns></returns>
public static Object SymbolName(Cons args, Environment environment)
{
return ((Symbol)args.First()).Name;
}
示例9: Read
/// <summary>
/// (read TextReader [eof])
/// </summary>
/// <param name="args"></param>
/// <param name="environment"></param>
/// <returns></returns>
public static Object Read(Cons args, Environment environment)
{
ReadTable readTable = (ReadTable)environment.GetValue(Symbol.FromName("*readtable*"));
TextReader textReader = (TextReader)args.First();
object eofValue = null;
if (args.Length() > 1)
eofValue = args.Second();
return Reader.Read(textReader, readTable, eofValue);
}
示例10: 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);
}
示例11: TypeOf
/// <summary>
/// (typeof symbol) Returns the type object of the same name as the given symbol.
/// </summary>
/// <example>(typeof Console)</example>
/// <param name="args"></param>
/// <param name="environment"></param>
/// <returns></returns>
public static Object TypeOf(Cons args, Environment environment)
{
Type type = TypeCache.Instance().FindType(args.First().ToString());
return (type);
}
示例12: CopyList
/// <summary>
/// Returns a shallow copy of the list given as its argument
/// </summary>
/// <param name="args"></param>
/// <param name="environment"></param>
/// <returns></returns>
public static Object CopyList(Cons args, Environment environment)
{
if (args.First() is Cons)
{
return ((Cons)args.First()).CopyList();
}
else
{
throw new LSharpException(args.First().ToString() + " is not a list.");
}
}
示例13: Map
/// <summary>
/// (map function list) Maps function to each element in list return a new
/// list of return values.
/// </summary>
/// <param name="args"></param>
/// <param name="environment"></param>
/// <returns></returns>
public static Object Map(Cons args, Environment environment)
{
if (args.Second() == null)
return null;
Cons temp = null;
foreach (object o in (IEnumerable)args.Second())
{
temp = new Cons(
Runtime.Apply( args.First(),new Cons(o),environment),
temp);
}
return temp.Reverse();
}
示例14: 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);
}
示例15: 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");
}