uCalc API Version: 2.1.3-preview.2 Released: 6/16/2026
Warning
uCalc API Preview Release Notice:The documentation describes the intended behavior of the API. The current preview build contains incomplete features, unoptimized performance, and is subject to breaking changes.
Rename
Method
Product:
Class:
Changes the name of an existing symbol, such as a variable, function, or operator, at runtime.
Syntax
Parameters
Return
Item
Returns the current Item instance to allow for method chaining.
Remarks
The Rename method provides a direct, efficient way to change the identifier of any named Item within the uCalc engine at runtime. This is a destructive operation: the original name is removed from the symbol table and is no longer valid.
This is commonly used for refactoring, adapting syntax, or wrapping existing functions with new behavior.
Impact on Dependencies
By default, uCalc expressions are statically bound when parsed. If you rename a function f to g, any existing expression that was already parsed to call f will not be automatically updated and will fail if evaluated. Renaming only affects expressions that are parsed after the rename operation has occurred.
To create dynamically-updating (reactive) expressions, you must define functions and operators with the overwrite: true flag. See DefineFunction() for more details.
⚖️ Comparative Analysis
It's important to choose the right tool for modifying symbols. Rename should be compared with Alias and text-based transformers.
vs. Alias()
- Rename:
A -> B(A is no longer valid). - Alias:
A -> B(Both A and B are valid, pointing to the same underlying item). - Use Case: Use
Renamefor permanent changes or to free up a name for reuse. UseAliasto provide synonyms or for backward compatibility.
- Rename:
- Rename: Operates directly on the symbol table. It is extremely fast and efficient.
- Transformer: Performs textual search-and-replace on the raw expression string before parsing. It is much slower and can have unintended side effects if the pattern is not specific enough.
- Use Case: Use
Renamefor simple name changes. Use aTransformerfor complex structural changes that involve more than just a name (e.g., reordering parameters, changing operators).
Examples
Renames the Cos function (which is in Radian) to CosR and defines Cos in Degrees
using uCalcSoftware;
var uc = new uCalc();
uc.DefineConstant("pi = Atan(1) * 4");
// Original Cosine behavior with Radian
Console.WriteLine(uc.EvalStr("Cos(pi)"));
Console.WriteLine(uc.EvalStr("Cos(180)"));
// Cos is renamed to CosR so that Cos can now be defined in Degree
uc.ItemOf("Cos").Rename("CosR");
uc.DefineFunction("Cos(x) = CosR(x*pi/180)");
// Now Cos is in Degree
Console.WriteLine(uc.EvalStr("Cos(pi)"));
Console.WriteLine(uc.EvalStr("Cos(180)"));
// This is the original function now named CosR
Console.WriteLine(uc.EvalStr("CosR(pi)"));
Console.WriteLine(uc.EvalStr("CosR(180)"));
// Note: Some functions may be overloaded, such as the Cos function in
// this example, which has a definition for Double and another for Complex.
// This example renames only the Double precision version.
// You can use NextOverload() and DataType() to pinpoint the one you want
-1
-0.59846006905785
0.99849714986386
-1
-1
-0.59846006905785 using uCalcSoftware; var uc = new uCalc(); uc.DefineConstant("pi = Atan(1) * 4"); // Original Cosine behavior with Radian Console.WriteLine(uc.EvalStr("Cos(pi)")); Console.WriteLine(uc.EvalStr("Cos(180)")); // Cos is renamed to CosR so that Cos can now be defined in Degree uc.ItemOf("Cos").Rename("CosR"); uc.DefineFunction("Cos(x) = CosR(x*pi/180)"); // Now Cos is in Degree Console.WriteLine(uc.EvalStr("Cos(pi)")); Console.WriteLine(uc.EvalStr("Cos(180)")); // This is the original function now named CosR Console.WriteLine(uc.EvalStr("CosR(pi)")); Console.WriteLine(uc.EvalStr("CosR(180)")); // Note: Some functions may be overloaded, such as the Cos function in // this example, which has a definition for Double and another for Complex. // This example renames only the Double precision version. // You can use NextOverload() and DataType() to pinpoint the one you want
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
uc.DefineConstant("pi = Atan(1) * 4");
// Original Cosine behavior with Radian
cout << uc.EvalStr("Cos(pi)") << endl;
cout << uc.EvalStr("Cos(180)") << endl;
// Cos is renamed to CosR so that Cos can now be defined in Degree
uc.ItemOf("Cos").Rename("CosR");
uc.DefineFunction("Cos(x) = CosR(x*pi/180)");
// Now Cos is in Degree
cout << uc.EvalStr("Cos(pi)") << endl;
cout << uc.EvalStr("Cos(180)") << endl;
// This is the original function now named CosR
cout << uc.EvalStr("CosR(pi)") << endl;
cout << uc.EvalStr("CosR(180)") << endl;
// Note: Some functions may be overloaded, such as the Cos function in
// this example, which has a definition for Double and another for Complex.
// This example renames only the Double precision version.
// You can use NextOverload() and DataType() to pinpoint the one you want
}
-1
-0.59846006905785
0.99849714986386
-1
-1
-0.59846006905785 #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; uc.DefineConstant("pi = Atan(1) * 4"); // Original Cosine behavior with Radian cout << uc.EvalStr("Cos(pi)") << endl; cout << uc.EvalStr("Cos(180)") << endl; // Cos is renamed to CosR so that Cos can now be defined in Degree uc.ItemOf("Cos").Rename("CosR"); uc.DefineFunction("Cos(x) = CosR(x*pi/180)"); // Now Cos is in Degree cout << uc.EvalStr("Cos(pi)") << endl; cout << uc.EvalStr("Cos(180)") << endl; // This is the original function now named CosR cout << uc.EvalStr("CosR(pi)") << endl; cout << uc.EvalStr("CosR(180)") << endl; // Note: Some functions may be overloaded, such as the Cos function in // this example, which has a definition for Double and another for Complex. // This example renames only the Double precision version. // You can use NextOverload() and DataType() to pinpoint the one you want }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
uc.DefineConstant("pi = Atan(1) * 4")
'// Original Cosine behavior with Radian
Console.WriteLine(uc.EvalStr("Cos(pi)"))
Console.WriteLine(uc.EvalStr("Cos(180)"))
'// Cos is renamed to CosR so that Cos can now be defined in Degree
uc.ItemOf("Cos").Rename("CosR")
uc.DefineFunction("Cos(x) = CosR(x*pi/180)")
'// Now Cos is in Degree
Console.WriteLine(uc.EvalStr("Cos(pi)"))
Console.WriteLine(uc.EvalStr("Cos(180)"))
'// This is the original function now named CosR
Console.WriteLine(uc.EvalStr("CosR(pi)"))
Console.WriteLine(uc.EvalStr("CosR(180)"))
'// Note: Some functions may be overloaded, such as the Cos function in
'// this example, which has a definition for Double and another for Complex.
'// This example renames only the Double precision version.
'// You can use NextOverload() and DataType() to pinpoint the one you want
End Sub
End Module
-1
-0.59846006905785
0.99849714986386
-1
-1
-0.59846006905785 Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() uc.DefineConstant("pi = Atan(1) * 4") '// Original Cosine behavior with Radian Console.WriteLine(uc.EvalStr("Cos(pi)")) Console.WriteLine(uc.EvalStr("Cos(180)")) '// Cos is renamed to CosR so that Cos can now be defined in Degree uc.ItemOf("Cos").Rename("CosR") uc.DefineFunction("Cos(x) = CosR(x*pi/180)") '// Now Cos is in Degree Console.WriteLine(uc.EvalStr("Cos(pi)")) Console.WriteLine(uc.EvalStr("Cos(180)")) '// This is the original function now named CosR Console.WriteLine(uc.EvalStr("CosR(pi)")) Console.WriteLine(uc.EvalStr("CosR(180)")) '// Note: Some functions may be overloaded, such as the Cos function in '// this example, which has a definition for Double and another for Complex. '// This example renames only the Double precision version. '// You can use NextOverload() and DataType() to pinpoint the one you want End Sub End Module