AjErl.Functions.CompileModuleFunction.Apply C# (CSharp) Method

Apply() public method

public Apply ( Context context, IList arguments ) : object
context Context
arguments IList
return object
        public object Apply(Context context, IList<object> arguments)
        {
            Atom atom = (Atom)arguments[0];
            Module module = this.machine.LoadModule(atom.Name);
            context.SetValue(module.Name, module);
            Tuple tuple = new Tuple(new object[] { new Atom("ok"), new Atom(module.Name) });
            return tuple;
        }

Usage Example

Ejemplo n.º 1
0
        public void CompileArithModule()
        {
            Machine machine = new Machine();
            CompileModuleFunction func = new CompileModuleFunction(machine);

            var result = func.Apply(machine.RootContext, new object[] { new Atom("arith") });

            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(Tuple));

            var tuple = (Tuple)result;

            Assert.AreEqual(2, tuple.Arity);

            var elem1 = tuple.ElementAt(0);

            Assert.IsNotNull(elem1);
            Assert.IsInstanceOfType(elem1, typeof(Atom));
            Assert.AreEqual("ok", ((Atom)elem1).Name);

            var elem2 = tuple.ElementAt(1);

            Assert.IsNotNull(elem2);
            Assert.IsInstanceOfType(elem2, typeof(Atom));
            Assert.AreEqual("arith", ((Atom)elem2).Name);

            var result2 = machine.RootContext.GetValue("arith");
            Assert.IsNotNull(result2);
            Assert.IsInstanceOfType(result2, typeof(Module));
            Assert.AreEqual("arith", ((Module)result2).Name);
        }
CompileModuleFunction