public void SetGlobalValueInTopEnvironmentUsingChild() { ValueEnvironment child = new ValueEnvironment(this.environment); child.SetGlobalValue("foo", "bar"); Assert.AreEqual("bar", this.environment.GetValue("foo")); Assert.AreEqual("bar", child.GetValue("foo")); }
public void SetGlobalAndLocalValue() { ValueEnvironment child = new ValueEnvironment(this.environment); child.SetGlobalValue("foo", "bar"); child.SetValue("foo", "bar2"); Assert.AreEqual("bar", this.environment.GetValue("foo")); Assert.AreEqual("bar2", child.GetValue("foo")); }
public override object Execute(List arguments, ValueEnvironment environment) { Identifier atom; object arglist; List body; atom = (Identifier)arguments.First; arglist = arguments.Next.First; body = arguments.Next.Next; if (body == null) { object result = Machine.Evaluate(arglist, environment); environment.SetGlobalValue(atom.Name, result); return(result); } SubrClosure closure = new SubrClosure(arglist, environment, body); environment.SetGlobalValue(atom.Name, closure); return(closure); }
public override object Execute(List args, ValueEnvironment env) { Identifier atom; object arglist; List body; atom = (Identifier)args.First; arglist = args.Next.First; body = args.Next.Next; FSubrMacroClosure closure = new FSubrMacroClosure(arglist, env, body); env.SetGlobalValue(atom.Name, closure); return(closure); }
public override object Execute(List arguments, ValueEnvironment environment) { Identifier atom; List arglist; List body; atom = (Identifier)arguments.First; arglist = (List)arguments.Next.First; body = arguments.Next.Next; if (!Predicates.IsIdentifier(arglist.First) || !Predicates.IsNil(arglist.Rest)) { throw new ArgumentException("df needs a unique parameter"); } SubrNClosure closure = new SubrNClosure((Identifier)arglist.First, environment, body); environment.SetGlobalValue(atom.ToString(), closure); return(closure); }