本文整理汇总了C#中LSharp.Cons类的典型用法代码示例。如果您正苦于以下问题:C# Cons类的具体用法?C# Cons怎么用?C# Cons使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Cons类属于LSharp命名空间,在下文中一共展示了Cons类的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: And
/// <summary>
/// Returns true if all arguments are true, false otherwise.
/// Performs short circuit evaluation on its arguments.
/// </summary>
/// <param name="args"></param>
/// <param name="environment"></param>
/// <returns></returns>
public static Object And(Cons args, Environment environment)
{
foreach (Object item in args)
{
if (Conversions.ObjectToBoolean(Runtime.Eval(item,environment)) == false)
return false;
}
return true;
}
示例3: 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;
}
示例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: EvalList
/// <summary>
/// Maps eval to a list of expressions
/// </summary>
/// <param name="list"></param>
/// <param name="environment"></param>
/// <returns></returns>
public static Cons EvalList(object list, Environment environment)
{
if (list == null)
return null;
object result = null;
foreach (object item in (Cons)list )
{
result = new Cons(Eval(item,environment) ,result);
}
return ((Cons)result).Reverse();
}
示例6: Expand
public Object Expand(Cons arguments)
{
// Create a new lexical environment
Environment localEnvironment = new Environment(environment);
Primitives.ProcessArguments(argumentNames, arguments, localEnvironment);
object result = null;
foreach (object o in body)
{
result = Runtime.Eval(o,localEnvironment);
}
return result;
}
示例7: MoveNext
public bool MoveNext()
{
object o = list.Cdr();
if (o==null)
return false;
if (o is Cons)
{
list = (Cons)o;
}
else
{
list = new Cons(o);
}
return true;
}
示例8: Invoke
/// <summary>
/// Invokes the closure with arguments bound to the values specified in the
/// argument list
/// </summary>
/// <param name="arguments"></param>
/// <returns></returns>
public Object Invoke(Cons arguments)
{
// Create a new lexical environment
Environment localEnvironment = new Environment(environment);
Primitives.ProcessArguments(argumentNames, arguments, localEnvironment);
// Evaluate the body within this lexical environment
object result = null;
if (body != null)
{
foreach (object o in body)
{
result = Runtime.Eval(o, localEnvironment);
}
}
return result;
}
示例9: 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;
}
}
示例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: MacroExpand
public static Object MacroExpand(Cons args, Environment environment)
{
Macro macro = (Macro)args.First();
Cons arguments = (Cons)args.Rest();
return macro.Expand(arguments);
}
示例12: List
/// <summary>
/// (list object*)
/// Creates a new cons, an ordered list with each object as a member.
/// </summary>
/// <param name="args"></param>
/// <param name="environment"></param>
/// <returns></returns>
public static Object List(Cons args, Environment environment)
{
return args;
}
示例13: Load
/// <summary>
/// (load filename) Loads and evaluates all statements in the given
/// filename which must be a text file.
/// </summary>
/// <param name="args"></param>
/// <param name="environment"></param>
/// <returns></returns>
public static Object Load(Cons args, Environment environment)
{
object filename = args.First();
if (filename is string)
{
TextReader textReader;
// 9/29/11: Enabled "short" filenames (adds .ls if needed)
if (System.IO.File.Exists((string)filename))
textReader = new StreamReader((string)filename);
else if (File.Exists(filename + ".ls")) // short file specified?
textReader = new StreamReader((string)filename + ".ls");
else
throw new LSharpException("Cannot find file " + filename);
string buffer = textReader.ReadToEnd();
textReader.Close();
// We want to evaluate the whole file, so there is an implicit do
// which we now make explicit
string expression = string.Format("(do {0}\n)",buffer);
object input = Reader.Read(new StringReader(expression),ReadTable.DefaultReadTable());
object output = Runtime.Eval(input, environment);
return output;
}
throw new LSharpException(String.Format("Load: {0} is not a string", filename));
}
示例14: Eval
/// <summary>
/// Evaluates an LSharp expression in a given environment
/// </summary>
/// <param name="args"></param>
/// <param name="environment"></param>
/// <returns></returns>
public static Object Eval(Cons args, Environment environment)
{
if (args.Length() == 1)
return Runtime.Eval(args.First(), environment);
else
throw new LSharpException("Incorrect arguments given to eval");
}
示例15: 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;
}