AjErl.Language.MultiFunction.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)
        {
            foreach (var function in this.functions)
            {
                var newcontext = function.MakeContext(arguments);

                if (newcontext != null)
                    return function.Evaluate(newcontext);
            }

            throw new Exception("no function clause to match");
        }

Usage Example

示例#1
0
        public void EvaluateMultiFunctionWithTwoFunctions()
        {
            Function func1 = this.MakeFunction("f(0) -> 1.");
            Function func2 = this.MakeFunction("f(1) -> 2.");
            MultiFunction mfunc = new MultiFunction(new Function[] { func1, func2 });

            Assert.AreEqual(2, mfunc.Apply(null, new object[] { 1 }));
        }
All Usage Examples Of AjErl.Language.MultiFunction::Apply