private static ICallable BuildFactorialFunction(IContext context)
{
IExpression condition = new CompareExpression(ComparisonOperator.LessEqual, new VariableExpression("n"), new ConstantExpression(1));
ICommand return1 = new ReturnCommand(new ConstantExpression(1));
ICommand return2 = new ReturnCommand(
new ArithmeticBinaryExpression(
ArithmeticOperator.Multiply,
new VariableExpression("n"),
new InvokeExpression(new VariableExpression("Factorial"), new IExpression[] { new ArithmeticBinaryExpression(ArithmeticOperator.Subtract, new VariableExpression("n"), new ConstantExpression(1)) })));
ICommand ifcmd = new IfCommand(condition, return1, return2);
ICallable factorial = new Function(new string[] { "n" }, ifcmd, context);
return factorial;
}