using uCalcSoftware; var uc = new uCalc(); static void MyRepeat(uCalc.Callback cb) { var count = cb.ArgInt32(1); var action = cb.ArgExpr(2); for (int i = 1; i <= count; i++) { action.Execute(); // Evaluate the passed-in expression } } // Define a variable that our action will modify uc.DefineVariable("counter = 0"); // Define the function. The 'action' parameter is marked with ByExpr // to ensure it's passed as an unevaluated expression object. uc.DefineFunction("Repeat(count As Int, ByExpr action)", MyRepeat); // Call the custom Repeat function. The expression 'counter++' is not // evaluated here; it's passed to the callback to be executed in a loop. uc.Eval("Repeat(5, counter++)"); // Verify the side effect Console.WriteLine($"Final counter value: {uc.Eval("counter")}");