public void ValueNodeCloneTest() { tlog.Debug(tag, $"ValueNodeCloneTest START"); try { var node = new ValueNode("1", null, 1, 1); var ret = node.Clone(); Assert.IsNotNull(ret, "Should not be equal"); } catch (Exception e) { tlog.Debug(tag, e.Message.ToString()); Assert.Fail("Caught Exception : Failed!"); } tlog.Debug(tag, $"ValueNodeCloneTest END"); }
public static object Lambda(FunctionInvocation call) { ConsNode definedArgs = null; ConsNode definedBody = null; var info = new CloneInfo(); info.StackFrame = call.StackFrame; Scope creatorScope = call.StackFrame.Scope; ValueNode bodyNode = null; if (call.Args.Count == 2) { definedArgs = new ConsNode(); definedArgs.Args = new List <object>(); var varNode = new SymbolNode(); varNode.Name = "item"; definedArgs.Args.Add(varNode); bodyNode = call.Args[1] as ConsNode; } else if (call.Args.Count == 3) { if (call.Args[1] is ConsNode) { definedArgs = call.Args[1] as ConsNode; } else { definedArgs = Utils.Eval(call.StackFrame, call.Args[1]) as ConsNode; } bodyNode = call.Args[2] as ConsNode; } info.LocalIdentifiers = definedArgs.Args.Cast <SymbolNode>().Select(arg => Utils.CleanName(arg.Name)).ToList(); //make snapshot of bound non local identifiers definedBody = bodyNode.Clone(info) as ConsNode; LispFunc lispFunc = kall => { //todo: verify arg list, only identifiers allowed Scope oldScope = kall.StackFrame.Scope; var newScope = new Scope(creatorScope); Utils.SetupArgs(definedArgs, kall, newScope); kall.StackFrame.Scope = newScope; //call the body object res = definedBody.Eval(kall.StackFrame); Utils.TearDownArgs(definedArgs, kall); kall.StackFrame.Scope = oldScope; return(res); }; return(lispFunc); }