public void SetMemory(string name, Thing value) { if (memory.ContainsKey(name)) { memory[name] = value; } else { memory.Add(name, value); } }
/// <summary> /// Evaluates all functions in left or right so that they only contain simple types. /// Only called at Runtime /// f:add[n:3][n:4] becomes [n:7]. /// Changes left and right properties /// </summary> protected void EvalArgumentsRecursive(ProgramRunner runner) { if (left.IsType(typeof(Function))) { left = ((Function)left).Eval(runner); } if (right.IsType(typeof(Function))) { right = ((Function)right).Eval(runner); } }
private static void PrintTreeNode(Thing thing, string prefix) { Console.WriteLine(prefix + "╞═" + thing.GetInfo()); if (typeof(Function).IsAssignableFrom(thing.GetType())) { Function function = (Function)thing; PrintTreeNode(function.left, prefix + "║ "); PrintTreeNode(function.right, prefix + "║ "); } }
public override Function GetNew(Thing left, Thing right) => new Until(left, right);
public Until(Thing left, Thing right) : base(left, right) { }
/// <summary> /// Used for prototype design pattern. Override from child class to return child type /// </summary> /// <returns>New function of (left, right)</returns> public virtual Function GetNew(Thing left, Thing right) { return new Function(left, right); }
public Function(Thing left, Thing right) { this.left = left; this.right = right; }
public override Function GetNew(Thing left, Thing right) => new LambdaFunction(func, left, right);
public LambdaFunction(Func<Thing, Thing, ProgramRunner, Thing> func, Thing left, Thing right) : base(left, right) { this.func = func; }
public MathFunction(Func<double, double, double> func, Thing left, Thing right) : base(left, right) { this.func = func; }
public Set(Thing left, Thing right) : base(left, right) { }