uCalc API Version: 5.7.0-preview.1 Released: 7/30/2026
Warning
uCalc API Preview Release Notice:This preview documentation describes the intended behavior of the API. It is not fully accurate or complete.The current preview build contains incomplete features, unoptimized performance, and is subject to breaking changes.Use of the preview version in your production code is not recommended.
Product:
Class:
Executes a pre-parsed expression without returning a value, optimized for operations valued for their side effects rather than their result.
This method does not return a value.
The Execute method evaluates a pre-parsed Expression for its side effects, discarding any potential return value. It is the ideal choice for performance-critical loops or for running expressions that behave like imperative statements (e.g., variable assignments, increments) rather than mathematical calculations.
Execute vs. EvaluateChoosing between Execute and Evaluate is a key architectural decision. Execute signals an intent to modify state, while Evaluate signals an intent to compute a value.
| Feature | Execute() | Evaluate() / EvaluateStr() |
|---|---|---|
| Return Value | void (None) | A value (double, string, etc.) |
| Purpose | For side effects: changing variables, calling stateful functions. | For computation: calculating a result. |
| Performance | Higher. Bypasses the overhead of packaging and returning a value. | Slightly lower. Incurs cost to prepare and return the result. |
| Analogy | A void function in C# or a statement ending in a semicolon. | A function that returns a value. |
In most programming languages, there is a clear distinction between an expression (which evaluates to a value, e.g., 2 + 2) and a statement (which performs an action, e.g., x = 5;). uCalc is primarily an expression engine.
The Execute() method provides a bridge, allowing you to treat a parsed expression as a statement. This is powerful because it lets you build script-like, imperative logic that runs within the high-performance, sandboxed uCalc environment.
Execute: To increment a variable in a loop, you would need to constantly read its value from the engine, perform the calculation in your host language (C#/C++), and write it back. This involves significant overhead from crossing the boundary between your code and the uCalc engine.Execute: You can define the entire operation (e.g., "x = x + 1") within a single parsed expression and call Execute() repeatedly. The entire loop runs inside the highly optimized engine, resulting in better performance.ID: 22
using uCalcSoftware;
var uc = new uCalc();
var VariableX = uc.DefineVariable("x = 0");
var Total = uc.DefineVariable("Total");
string Expression = "x++; Total = Total + x^2 + 5";
var ParsedExpr = uc.Parse(Expression);
for (double x = 1; x <= 10; x++) {
// Execute() runs the parsed expression without the overhead of returning a value.
// This provides near-native performance for loops across C#, VB, and C++.
ParsedExpr.Execute();
// Evaluate string interpolation to output the final calculated total
Console.WriteLine(uc.EvalStr("$'{x} Sub total = {Total}'"));
}
Console.WriteLine(uc.EvalStr("$'Total = {Total}'"));
ParsedExpr.Release();
VariableX.Release();
1 Sub total = 6
2 Sub total = 15
3 Sub total = 29
4 Sub total = 50
5 Sub total = 80
6 Sub total = 121
7 Sub total = 175
8 Sub total = 244
9 Sub total = 330
10 Sub total = 435
Total = 435 using uCalcSoftware; var uc = new uCalc(); var VariableX = uc.DefineVariable("x = 0"); var Total = uc.DefineVariable("Total"); string Expression = "x++; Total = Total + x^2 + 5"; var ParsedExpr = uc.Parse(Expression); for (double x = 1; x <= 10; x++) { // Execute() runs the parsed expression without the overhead of returning a value. // This provides near-native performance for loops across C#, VB, and C++. ParsedExpr.Execute(); // Evaluate string interpolation to output the final calculated total Console.WriteLine(uc.EvalStr("$'{x} Sub total = {Total}'")); } Console.WriteLine(uc.EvalStr("$'Total = {Total}'")); ParsedExpr.Release(); VariableX.Release();
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
auto VariableX = uc.DefineVariable("x = 0");
auto Total = uc.DefineVariable("Total");
string Expression = "x++; Total = Total + x^2 + 5";
auto ParsedExpr = uc.Parse(Expression);
for (double x = 1; x <= 10; x++) {
// Execute() runs the parsed expression without the overhead of returning a value.
// This provides near-native performance for loops across C#, VB, and C++.
ParsedExpr.Execute();
// Evaluate string interpolation to output the final calculated total
cout << uc.EvalStr("$'{x} Sub total = {Total}'") << endl;
}
cout << uc.EvalStr("$'Total = {Total}'") << endl;
ParsedExpr.Release();
VariableX.Release();
}
1 Sub total = 6
2 Sub total = 15
3 Sub total = 29
4 Sub total = 50
5 Sub total = 80
6 Sub total = 121
7 Sub total = 175
8 Sub total = 244
9 Sub total = 330
10 Sub total = 435
Total = 435 #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; auto VariableX = uc.DefineVariable("x = 0"); auto Total = uc.DefineVariable("Total"); string Expression = "x++; Total = Total + x^2 + 5"; auto ParsedExpr = uc.Parse(Expression); for (double x = 1; x <= 10; x++) { // Execute() runs the parsed expression without the overhead of returning a value. // This provides near-native performance for loops across C#, VB, and C++. ParsedExpr.Execute(); // Evaluate string interpolation to output the final calculated total cout << uc.EvalStr("$'{x} Sub total = {Total}'") << endl; } cout << uc.EvalStr("$'Total = {Total}'") << endl; ParsedExpr.Release(); VariableX.Release(); }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Dim VariableX = uc.DefineVariable("x = 0")
Dim Total = uc.DefineVariable("Total")
Dim Expression As String = "x++; Total = Total + x^2 + 5"
Dim ParsedExpr = uc.Parse(Expression)
For x As Double = 1 To 10
'// Execute() runs the parsed expression without the overhead of returning a value.
'// This provides near-native performance for loops across C#, VB, and C++.
ParsedExpr.Execute()
'// Evaluate string interpolation to output the final calculated total
Console.WriteLine(uc.EvalStr("$'{x} Sub total = {Total}'"))
Next
Console.WriteLine(uc.EvalStr("$'Total = {Total}'"))
ParsedExpr.Release()
VariableX.Release()
End Sub
End Module
1 Sub total = 6
2 Sub total = 15
3 Sub total = 29
4 Sub total = 50
5 Sub total = 80
6 Sub total = 121
7 Sub total = 175
8 Sub total = 244
9 Sub total = 330
10 Sub total = 435
Total = 435 Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() Dim VariableX = uc.DefineVariable("x = 0") Dim Total = uc.DefineVariable("Total") Dim Expression As String = "x++; Total = Total + x^2 + 5" Dim ParsedExpr = uc.Parse(Expression) For x As Double = 1 To 10 '// Execute() runs the parsed expression without the overhead of returning a value. '// This provides near-native performance for loops across C#, VB, and C++. ParsedExpr.Execute() '// Evaluate string interpolation to output the final calculated total Console.WriteLine(uc.EvalStr("$'{x} Sub total = {Total}'")) Next Console.WriteLine(uc.EvalStr("$'Total = {Total}'")) ParsedExpr.Release() VariableX.Release() End Sub End Module