public static bool MatchObjects(object obj1, object obj2, Context context) { if (obj1 == null) if (obj2 == null) return true; else return false; if (obj1 is Variable) obj1 = (new VariableExpression((Variable)obj1)).Evaluate(context, true); if (obj2 is Variable) obj2 = (new VariableExpression((Variable)obj2)).Evaluate(context, true); if (obj1.Equals(obj2)) return true; if (obj1 is Variable && !(obj2 is Variable)) { Variable variable = (Variable)obj1; if (variable.Name != "_") context.SetValue(variable.Name, obj2); return true; } if (obj2 is Variable && !(obj1 is Variable)) { Variable variable = (Variable)obj2; context.SetValue(variable.Name, obj1); return true; } if (obj1 is Atom) if (obj2 is Atom) return ((Atom)obj1).Match((Atom)obj2); else return false; if (obj1 is List) if (obj2 is List) return ((List)obj1).Match((List)obj2, context); else return false; if (obj1 is Tuple) if (obj2 is Tuple) return ((Tuple)obj1).Match((Tuple)obj2, context); else return false; return false; }
public Machine() { this.rootcontext = new Context(); this.rootcontext.SetValue("c/1", new CompileModuleFunction(this)); this.rootcontext.SetValue("spawn/1", new SpawnFunction()); this.rootcontext.SetValue("self/0", new SelfFunction()); this.TextWriter = System.Console.Out; Module lists = new ListsModule(this.rootcontext); this.rootcontext.SetValue(lists.Name, lists); Module io = new IoModule(this); this.rootcontext.SetValue(io.Name, io); }
public void SetParent(Context parent) { this.parent = parent; }
public Context(Context parent = null, Module module = null) { this.parent = parent; this.module = module; }