Ejemplo n.º 1
0
        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"));
        }
Ejemplo n.º 2
0
        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"));
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        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);
        }