uCalc API Version: 2.1.3-preview.2 Released: 6/17/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.

IsDefault = [bool]

Property

Product: 

Fast Math Parser

Class: 

uCalcBase

Gets or sets whether the current uCalc instance is the active default for the current thread.

Remarks

⚙️ Managing the Default Instance

The IsDefault property gets or sets whether the current uCalc instance is the active default instance for the current thread. This default instance serves two main purposes:

  1. An Ambient Context: It acts as a convenient, globally accessible singleton. Components like uCalc.Expression or uCalc.String, when created without an explicit uCalc instance, automatically use the default one for their context.
  2. A Template for Clones: When you create a new uCalc instance via its constructor, it is initialized as a clone of the current default instance, inheriting all its functions, variables, and settings.

📖 The Default Instance Stack

Instead of a single, rigid global object, uCalc manages a stack of default instances using a LIFO (Last-In, First-Out) model. This provides a flexible, layered context system.

The instance at the top of the stack is the active default, which is returned by DefaultInstance.

🔧 Getter and Setter Behavior

  • Getter: var isDefault = myInstance.IsDefaultReturns true if myInstance is currently at the top of the default stack; otherwise, false.

  • Setter: myInstance.IsDefault = truePromotes myInstance to the top of the stack, making it the new active default.

  • Setter: myInstance.IsDefault = falseRemoves myInstance from the stack, wherever it may be. If it was the active default, the previously active instance is automatically restored.

⏱️ Scoped Defaults

The recommended way to manage temporary contexts is to combine @IsDefault with a using (var uc = new uCalc()) { block. When the scope is exited, the uCalc instance is automatically released and popped from the stack, cleanly restoring the previous default.

// Main context is active hereusing (var tempContext = new uCalc()) {    tempContext.IsDefault = true;    // tempContext is now the active default within this block}// The original default context is automatically restored here

✨ Best Practices

  • Avoid modifying the initial, built-in default instance directly. Instead, create a new, fully configured uCalc instance and set that as your application's primary default.
  • Use scoped using blocks or call @IsDefault(false) to clean up temporary defaults and prevent unexpected behavior.
  • Use DefaultCount() to inspect the size of the stack and DefaultClear() to reset the stack to its initial state.

🆚 Why uCalc? (Comparative Analysis)

In standard C# or C++, managing a "global" context requires careful design patterns.

  • Singleton Pattern: A traditional singleton is rigid and hard to test. uCalc's stack-based approach is more dynamic, allowing for temporary context overrides within specific scopes.
  • Dependency Injection (DI): While robust, DI adds boilerplate, especially for ubiquitous components like a parser. The default instance acts as a convenient "ambient context," simplifying code.
  • Static Class: This prevents having multiple, separate parser configurations running at the same time. uCalc's model allows for complete isolation between instances.

uCalc's default instance model offers a pragmatic middle ground, providing the convenience of a static/singleton approach while retaining the flexibility of having multiple, swappable configurations.

Examples

A simple check to see which uCalc instance is the default.
				
					using uCalcSoftware;

var uc = new uCalc();
// The implicit 'uc' object is not the default upon creation.
Console.WriteLine($"Is 'uc' the default instance? {uc.IsDefault}");

// Create a new uCalc instance. It also won't be the default.
var myCalc = new uCalc();
Console.WriteLine($"Is 'myCalc' the default instance? {myCalc.IsDefault}");

// Let's get the actual default instance and check it.
uCalc defaultInstance = uCalc.DefaultInstance;
Console.WriteLine($"Is the instance from uCalc.DefaultInstance the default? {defaultInstance.IsDefault}");
				
			
Is 'uc' the default instance? False
Is 'myCalc' the default instance? False
Is the instance from uCalc.DefaultInstance the default? True
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

#define tf(IsTrue) ((IsTrue) ? "True" : "False")

int main() {
   uCalc uc;
   // The implicit 'uc' object is not the default upon creation.
   cout << "Is 'uc' the default instance? " << tf(uc.IsDefault()) << endl;

   // Create a new uCalc instance. It also won't be the default.
   uCalc myCalc;
   cout << "Is 'myCalc' the default instance? " << tf(myCalc.IsDefault()) << endl;

   // Let's get the actual default instance and check it.
   uCalc defaultInstance = uCalc::DefaultInstance();
   cout << "Is the instance from uCalc.DefaultInstance the default? " << tf(defaultInstance.IsDefault()) << endl;
}
				
			
Is 'uc' the default instance? False
Is 'myCalc' the default instance? False
Is the instance from uCalc.DefaultInstance the default? True
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      '// The implicit 'uc' object is not the default upon creation.
      Console.WriteLine($"Is 'uc' the default instance? {uc.IsDefault}")
      
      '// Create a new uCalc instance. It also won't be the default.
      Dim myCalc As New uCalc()
      Console.WriteLine($"Is 'myCalc' the default instance? {myCalc.IsDefault}")
      
      '// Let's get the actual default instance and check it.
      Dim defaultInstance As uCalc = uCalc.DefaultInstance
      Console.WriteLine($"Is the instance from uCalc.DefaultInstance the default? {defaultInstance.IsDefault}")
   End Sub
End Module
				
			
Is 'uc' the default instance? False
Is 'myCalc' the default instance? False
Is the instance from uCalc.DefaultInstance the default? True
Manage different parser configurations by switching the default instance.
				
					using uCalcSoftware;

var uc = new uCalc();
// Setup a "Scientific" configuration
var scientificCalc = new uCalc();
scientificCalc.DefineFunction("sqrt(x) = x^0.5");
scientificCalc.DefineVariable("pi = 3.14159");

// Setup a "Financial" configuration
var financialCalc = new uCalc();
financialCalc.DefineFunction("tax(amount, rate) = amount * (rate/100)");

// Set the scientific calculator as the default
scientificCalc.IsDefault = true;
Console.WriteLine($"Current default is scientific? {scientificCalc.IsDefault}");

// Components that rely on the default instance now use the scientific setup.
uCalc.Expression expr1 = "2 * pi";
Console.WriteLine($"2 * pi = {expr1.Evaluate()}");

// Now, switch the default to the financial calculator
financialCalc.IsDefault = true;
Console.WriteLine($"Current default is scientific? {scientificCalc.IsDefault}"); // Should be false now
Console.WriteLine($"Current default is financial? {financialCalc.IsDefault}");

// New components will use the financial setup.
uCalc.Expression expr2 = "tax(50000, 20)";
Console.WriteLine($"Tax on 50000 at 20% = {expr2.Evaluate()}");
				
			
Current default is scientific? True
2 * pi = 6.28318
Current default is scientific? False
Current default is financial? True
Tax on 50000 at 20% = 10000
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

#define tf(IsTrue) ((IsTrue) ? "True" : "False")

int main() {
   uCalc uc;
   // Setup a "Scientific" configuration
   uCalc scientificCalc;
   scientificCalc.DefineFunction("sqrt(x) = x^0.5");
   scientificCalc.DefineVariable("pi = 3.14159");

   // Setup a "Financial" configuration
   uCalc financialCalc;
   financialCalc.DefineFunction("tax(amount, rate) = amount * (rate/100)");

   // Set the scientific calculator as the default
   scientificCalc.IsDefault(true);
   cout << "Current default is scientific? " << tf(scientificCalc.IsDefault()) << endl;

   // Components that rely on the default instance now use the scientific setup.
   uCalc::Expression expr1 = "2 * pi";
   cout << "2 * pi = " << expr1.Evaluate() << endl;

   // Now, switch the default to the financial calculator
   financialCalc.IsDefault(true);
   cout << "Current default is scientific? " << tf(scientificCalc.IsDefault()) << endl; // Should be false now
   cout << "Current default is financial? " << tf(financialCalc.IsDefault()) << endl;

   // New components will use the financial setup.
   uCalc::Expression expr2 = "tax(50000, 20)";
   cout << "Tax on 50000 at 20% = " << expr2.Evaluate() << endl;
}
				
			
Current default is scientific? True
2 * pi = 6.28318
Current default is scientific? False
Current default is financial? True
Tax on 50000 at 20% = 10000
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      '// Setup a "Scientific" configuration
      Dim scientificCalc As New uCalc()
      scientificCalc.DefineFunction("sqrt(x) = x^0.5")
      scientificCalc.DefineVariable("pi = 3.14159")
      
      '// Setup a "Financial" configuration
      Dim financialCalc As New uCalc()
      financialCalc.DefineFunction("tax(amount, rate) = amount * (rate/100)")
      
      '// Set the scientific calculator as the default
      scientificCalc.IsDefault = true
      Console.WriteLine($"Current default is scientific? {scientificCalc.IsDefault}")
      
      '// Components that rely on the default instance now use the scientific setup.
      Dim expr1 As uCalc.Expression = "2 * pi"
      Console.WriteLine($"2 * pi = {expr1.Evaluate()}")
      
      '// Now, switch the default to the financial calculator
      financialCalc.IsDefault = true
      Console.WriteLine($"Current default is scientific? {scientificCalc.IsDefault}") '// Should be false now
      Console.WriteLine($"Current default is financial? {financialCalc.IsDefault}")
      
      '// New components will use the financial setup.
      Dim expr2 As uCalc.Expression = "tax(50000, 20)"
      Console.WriteLine($"Tax on 50000 at 20% = {expr2.Evaluate()}")
   End Sub
End Module
				
			
Current default is scientific? True
2 * pi = 6.28318
Current default is scientific? False
Current default is financial? True
Tax on 50000 at 20% = 10000
Internal Test: Verify the stack-like behavior of the default instance list.
				
					using uCalcSoftware;

var uc = new uCalc();
// Define a variable in the original default to distinguish it.
// Note: This variable won't exist in the implicit 'uc' instance.
uCalc.DefaultInstance.DefineVariable("id='Original'");
Console.WriteLine($"Initial default: {uCalc.DefaultInstance.EvalStr("id")}");

var ucA = new uCalc();
ucA.DefineVariable("id='A'");
ucA.IsDefault = true; // Default stack: [Original, A]
Console.WriteLine($"Current default: {uCalc.DefaultInstance.EvalStr("id")}");

var ucB = new uCalc();
ucB.DefineVariable("id='B'");
ucB.IsDefault = true; // Default stack: [Original, A, B]
Console.WriteLine($"Current default: {uCalc.DefaultInstance.EvalStr("id")}");

var ucC = new uCalc();
ucC.DefineVariable("id='C'");
ucC.IsDefault = true; // Default stack: [Original, A, B, C]
Console.WriteLine($"Current default: {uCalc.DefaultInstance.EvalStr("id")}");

Console.WriteLine("--- Unsetting instances ---");
// Unset B. The default should remain C.
ucB.IsDefault = false;
Console.WriteLine($"After unsetting B, current default: {uCalc.DefaultInstance.EvalStr("id")}");

// Unset C. The default should revert to A.
ucC.IsDefault = false;
Console.WriteLine($"After unsetting C, current default: {uCalc.DefaultInstance.EvalStr("id")}");

// Unset A. Reverts to the original default.
ucA.IsDefault = false;
Console.WriteLine($"After unsetting A, current default: {uCalc.DefaultInstance.EvalStr("id")}");
				
			
Initial default: Original
Current default: A
Current default: B
Current default: C
--- Unsetting instances ---
After unsetting B, current default: C
After unsetting C, current default: A
After unsetting A, current default: Original
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   // Define a variable in the original default to distinguish it.
   // Note: This variable won't exist in the implicit 'uc' instance.
   uCalc::DefaultInstance().DefineVariable("id='Original'");
   cout << "Initial default: " << uCalc::DefaultInstance().EvalStr("id") << endl;

   uCalc ucA;
   ucA.DefineVariable("id='A'");
   ucA.IsDefault(true); // Default stack: [Original, A]
   cout << "Current default: " << uCalc::DefaultInstance().EvalStr("id") << endl;

   uCalc ucB;
   ucB.DefineVariable("id='B'");
   ucB.IsDefault(true); // Default stack: [Original, A, B]
   cout << "Current default: " << uCalc::DefaultInstance().EvalStr("id") << endl;

   uCalc ucC;
   ucC.DefineVariable("id='C'");
   ucC.IsDefault(true); // Default stack: [Original, A, B, C]
   cout << "Current default: " << uCalc::DefaultInstance().EvalStr("id") << endl;

   cout << "--- Unsetting instances ---" << endl;
   // Unset B. The default should remain C.
   ucB.IsDefault(false);
   cout << "After unsetting B, current default: " << uCalc::DefaultInstance().EvalStr("id") << endl;

   // Unset C. The default should revert to A.
   ucC.IsDefault(false);
   cout << "After unsetting C, current default: " << uCalc::DefaultInstance().EvalStr("id") << endl;

   // Unset A. Reverts to the original default.
   ucA.IsDefault(false);
   cout << "After unsetting A, current default: " << uCalc::DefaultInstance().EvalStr("id") << endl;
}
				
			
Initial default: Original
Current default: A
Current default: B
Current default: C
--- Unsetting instances ---
After unsetting B, current default: C
After unsetting C, current default: A
After unsetting A, current default: Original
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      '// Define a variable in the original default to distinguish it.
      '// Note: This variable won't exist in the implicit 'uc' instance.
      uCalc.DefaultInstance.DefineVariable("id='Original'")
      Console.WriteLine($"Initial default: {uCalc.DefaultInstance.EvalStr("id")}")
      
      Dim ucA As New uCalc()
      ucA.DefineVariable("id='A'")
      ucA.IsDefault = true '// Default stack: [Original, A]
      Console.WriteLine($"Current default: {uCalc.DefaultInstance.EvalStr("id")}")
      
      Dim ucB As New uCalc()
      ucB.DefineVariable("id='B'")
      ucB.IsDefault = true '// Default stack: [Original, A, B]
      Console.WriteLine($"Current default: {uCalc.DefaultInstance.EvalStr("id")}")
      
      Dim ucC As New uCalc()
      ucC.DefineVariable("id='C'")
      ucC.IsDefault = true '// Default stack: [Original, A, B, C]
      Console.WriteLine($"Current default: {uCalc.DefaultInstance.EvalStr("id")}")
      
      Console.WriteLine("--- Unsetting instances ---")
      '// Unset B. The default should remain C.
      ucB.IsDefault = false
      Console.WriteLine($"After unsetting B, current default: {uCalc.DefaultInstance.EvalStr("id")}")
      
      '// Unset C. The default should revert to A.
      ucC.IsDefault = false
      Console.WriteLine($"After unsetting C, current default: {uCalc.DefaultInstance.EvalStr("id")}")
      
      '// Unset A. Reverts to the original default.
      ucA.IsDefault = false
      Console.WriteLine($"After unsetting A, current default: {uCalc.DefaultInstance.EvalStr("id")}")
   End Sub
End Module
				
			
Initial default: Original
Current default: A
Current default: B
Current default: C
--- Unsetting instances ---
After unsetting B, current default: C
After unsetting C, current default: A
After unsetting A, current default: Original
Checking if a uCalc object is the default with IsDefault
				
					using uCalcSoftware;

var uc = new uCalc();
var Status = uc.DefineVariable("Status As Bool");
Console.WriteLine(Status.ValueBool());

var MyuCalc = new uCalc();

Status.ValueBool(MyuCalc.IsDefault);
Console.WriteLine(uc.EvalStr("$'MyuCalc is the current default? {Status}'"));

MyuCalc.IsDefault = true;
Status.ValueBool(MyuCalc.IsDefault);

Console.WriteLine(uc.EvalStr("$'MyuCalc is the current default? {Status}'"));
				
			
False
MyuCalc is the current default? false
MyuCalc is the current default? true
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

#define tf(IsTrue) ((IsTrue) ? "True" : "False")

int main() {
   uCalc uc;
   auto Status = uc.DefineVariable("Status As Bool");
   cout << tf(Status.ValueBool()) << endl;

   uCalc MyuCalc;

   Status.ValueBool(MyuCalc.IsDefault());
   cout << uc.EvalStr("$'MyuCalc is the current default? {Status}'") << endl;

   MyuCalc.IsDefault(true);
   Status.ValueBool(MyuCalc.IsDefault());

   cout << uc.EvalStr("$'MyuCalc is the current default? {Status}'") << endl;
}
				
			
False
MyuCalc is the current default? false
MyuCalc is the current default? true
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      Dim Status = uc.DefineVariable("Status As Bool")
      Console.WriteLine(Status.ValueBool())
      
      Dim MyuCalc As New uCalc()
      
      Status.ValueBool(MyuCalc.IsDefault)
      Console.WriteLine(uc.EvalStr("$'MyuCalc is the current default? {Status}'"))
      
      MyuCalc.IsDefault = true
      Status.ValueBool(MyuCalc.IsDefault)
      
      Console.WriteLine(uc.EvalStr("$'MyuCalc is the current default? {Status}'"))
   End Sub
End Module
				
			
False
MyuCalc is the current default? false
MyuCalc is the current default? true
Setting uCalc default with uCalc.IsDefault()
				
					using uCalcSoftware;

var uc = new uCalc();
var uCalcA = new uCalc();
var uCalcB = new uCalc();
var uCalcC = new uCalc();

uCalcA.DefineVariable("MyVar = 'I was cloned from uCalcA'");
uCalcB.DefineVariable("MyVar = 'I was cloned from uCalcB'");
uCalcC.DefineVariable("MyVar = 'I was cloned from uCalcC'");

uCalcA.IsDefault = true;
Console.WriteLine(uCalc.DefaultInstance.EvalStr("MyVar"));

uCalcB.IsDefault = true;
Console.WriteLine(uCalc.DefaultInstance.EvalStr("MyVar"));

uCalcC.IsDefault = true;
Console.WriteLine(uCalc.DefaultInstance.EvalStr("MyVar"));

Console.WriteLine("---");

// Now unsetting uCalc objects as default
uCalcC.IsDefault = false;
Console.WriteLine(uCalc.DefaultInstance.EvalStr("MyVar"));

uCalcB.IsDefault = false;
Console.WriteLine(uCalc.DefaultInstance.EvalStr("MyVar"));

uCalcA.IsDefault = false;
Console.WriteLine(uCalc.DefaultInstance.EvalStr("MyVar"));


				
			
I was cloned from uCalcA
I was cloned from uCalcB
I was cloned from uCalcC
---
I was cloned from uCalcB
I was cloned from uCalcA
Undefined identifier
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   uCalc uCalcA;
   uCalc uCalcB;
   uCalc uCalcC;

   uCalcA.DefineVariable("MyVar = 'I was cloned from uCalcA'");
   uCalcB.DefineVariable("MyVar = 'I was cloned from uCalcB'");
   uCalcC.DefineVariable("MyVar = 'I was cloned from uCalcC'");

   uCalcA.IsDefault(true);
   cout << uCalc::DefaultInstance().EvalStr("MyVar") << endl;

   uCalcB.IsDefault(true);
   cout << uCalc::DefaultInstance().EvalStr("MyVar") << endl;

   uCalcC.IsDefault(true);
   cout << uCalc::DefaultInstance().EvalStr("MyVar") << endl;

   cout << "---" << endl;

   // Now unsetting uCalc objects as default
   uCalcC.IsDefault(false);
   cout << uCalc::DefaultInstance().EvalStr("MyVar") << endl;

   uCalcB.IsDefault(false);
   cout << uCalc::DefaultInstance().EvalStr("MyVar") << endl;

   uCalcA.IsDefault(false);
   cout << uCalc::DefaultInstance().EvalStr("MyVar") << endl;


}
				
			
I was cloned from uCalcA
I was cloned from uCalcB
I was cloned from uCalcC
---
I was cloned from uCalcB
I was cloned from uCalcA
Undefined identifier
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      Dim uCalcA As New uCalc()
      Dim uCalcB As New uCalc()
      Dim uCalcC As New uCalc()
      
      uCalcA.DefineVariable("MyVar = 'I was cloned from uCalcA'")
      uCalcB.DefineVariable("MyVar = 'I was cloned from uCalcB'")
      uCalcC.DefineVariable("MyVar = 'I was cloned from uCalcC'")
      
      uCalcA.IsDefault = true
      Console.WriteLine(uCalc.DefaultInstance.EvalStr("MyVar"))
      
      uCalcB.IsDefault = true
      Console.WriteLine(uCalc.DefaultInstance.EvalStr("MyVar"))
      
      uCalcC.IsDefault = true
      Console.WriteLine(uCalc.DefaultInstance.EvalStr("MyVar"))
      
      Console.WriteLine("---")
      
      '// Now unsetting uCalc objects as default
      uCalcC.IsDefault = false
      Console.WriteLine(uCalc.DefaultInstance.EvalStr("MyVar"))
      
      uCalcB.IsDefault = false
      Console.WriteLine(uCalc.DefaultInstance.EvalStr("MyVar"))
      
      uCalcA.IsDefault = false
      Console.WriteLine(uCalc.DefaultInstance.EvalStr("MyVar"))
      
      
   End Sub
End Module
				
			
I was cloned from uCalcA
I was cloned from uCalcB
I was cloned from uCalcC
---
I was cloned from uCalcB
I was cloned from uCalcA
Undefined identifier
Using the default uCalc.GetDefaultInstance() instance
				
					using uCalcSoftware;

var uc = new uCalc();
uCalc.DefaultInstance.DefineVariable("instance = 'original default'");

var ucB = new uCalc();
var ucC = new uCalc();
var ucD = new uCalc();

ucB.Eval("instance = 'B derived from -> ' + instance");
ucC.Eval("instance = 'C derived from -> ' + instance");
ucD.Eval("instance = 'D derived from -> ' + instance");

ucC.IsDefault = true;

var ucE = new uCalc();
ucE.Eval("instance = 'E derived from -> ' + instance");

Console.WriteLine(uCalc.DefaultInstance.EvalStr("'Default: ' + instance"));

Console.WriteLine(uc.EvalStr("instance")); // Note: this is not, nor was the default
Console.WriteLine(ucB.EvalStr("instance"));
Console.WriteLine(ucC.EvalStr("instance"));
Console.WriteLine(ucD.EvalStr("instance"));
Console.WriteLine(ucE.EvalStr("instance"));

// Note: Unlike this example, it is generally best to always
// create a new instance first and then set it as default
				
			
Default: C derived from -> original default
Undefined identifier
B derived from -> original default
C derived from -> original default
D derived from -> original default
E derived from -> C derived from -> original default
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   uCalc::DefaultInstance().DefineVariable("instance = 'original default'");

   uCalc ucB;
   uCalc ucC;
   uCalc ucD;

   ucB.Eval("instance = 'B derived from -> ' + instance");
   ucC.Eval("instance = 'C derived from -> ' + instance");
   ucD.Eval("instance = 'D derived from -> ' + instance");

   ucC.IsDefault(true);

   uCalc ucE;
   ucE.Eval("instance = 'E derived from -> ' + instance");

   cout << uCalc::DefaultInstance().EvalStr("'Default: ' + instance") << endl;

   cout << uc.EvalStr("instance") << endl; // Note: this is not, nor was the default
   cout << ucB.EvalStr("instance") << endl;
   cout << ucC.EvalStr("instance") << endl;
   cout << ucD.EvalStr("instance") << endl;
   cout << ucE.EvalStr("instance") << endl;

   // Note: Unlike this example, it is generally best to always
   // create a new instance first and then set it as default
}
				
			
Default: C derived from -> original default
Undefined identifier
B derived from -> original default
C derived from -> original default
D derived from -> original default
E derived from -> C derived from -> original default
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      uCalc.DefaultInstance.DefineVariable("instance = 'original default'")
      
      Dim ucB As New uCalc()
      Dim ucC As New uCalc()
      Dim ucD As New uCalc()
      
      ucB.Eval("instance = 'B derived from -> ' + instance")
      ucC.Eval("instance = 'C derived from -> ' + instance")
      ucD.Eval("instance = 'D derived from -> ' + instance")
      
      ucC.IsDefault = true
      
      Dim ucE As New uCalc()
      ucE.Eval("instance = 'E derived from -> ' + instance")
      
      Console.WriteLine(uCalc.DefaultInstance.EvalStr("'Default: ' + instance"))
      
      Console.WriteLine(uc.EvalStr("instance")) '// Note: this is not, nor was the default
      Console.WriteLine(ucB.EvalStr("instance"))
      Console.WriteLine(ucC.EvalStr("instance"))
      Console.WriteLine(ucD.EvalStr("instance"))
      Console.WriteLine(ucE.EvalStr("instance"))
      
      '// Note: Unlike this example, it is generally best to always
      '// create a new instance first and then set it as default
   End Sub
End Module
				
			
Default: C derived from -> original default
Undefined identifier
B derived from -> original default
C derived from -> original default
D derived from -> original default
E derived from -> C derived from -> original default
Setting default uCalc instance with uCalc.IsDefault(); also clearing all uCalc instances from default list
				
					using uCalcSoftware;

var uc = new uCalc();
uCalc.DefaultInstance.DefineVariable("val = 'original default'");
Console.WriteLine(uCalc.DefaultInstance.EvalStr("val"));

uc.DefineVariable("val = 'uc'");
uc.IsDefault = true;
Console.WriteLine(uCalc.DefaultInstance.EvalStr("val"));

var ucB = new uCalc();
ucB.DefineVariable("val = 'ucB'");
ucB.IsDefault = true;
Console.WriteLine(uCalc.DefaultInstance.EvalStr("val"));

var ucC = new uCalc();
ucC.DefineVariable("val = 'ucC'");
ucC.IsDefault = true;
Console.WriteLine(uCalc.DefaultInstance.EvalStr("val"));

uCalc.DefaultClear();

// The original unnamed default instance is reset so user variable val no longer exists
Console.WriteLine(uCalc.DefaultInstance.EvalStr("val"));

// The other instances are removed from Default list but remain active
Console.WriteLine(uc.EvalStr("val"));
Console.WriteLine(ucB.EvalStr("val"));
Console.WriteLine(ucC.EvalStr("val"));
				
			
original default
uc
ucB
ucC
Undefined identifier
uc
ucB
ucC
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   uCalc::DefaultInstance().DefineVariable("val = 'original default'");
   cout << uCalc::DefaultInstance().EvalStr("val") << endl;

   uc.DefineVariable("val = 'uc'");
   uc.IsDefault(true);
   cout << uCalc::DefaultInstance().EvalStr("val") << endl;

   uCalc ucB;
   ucB.DefineVariable("val = 'ucB'");
   ucB.IsDefault(true);
   cout << uCalc::DefaultInstance().EvalStr("val") << endl;

   uCalc ucC;
   ucC.DefineVariable("val = 'ucC'");
   ucC.IsDefault(true);
   cout << uCalc::DefaultInstance().EvalStr("val") << endl;

   uCalc::DefaultClear();

   // The original unnamed default instance is reset so user variable val no longer exists
   cout << uCalc::DefaultInstance().EvalStr("val") << endl;

   // The other instances are removed from Default list but remain active
   cout << uc.EvalStr("val") << endl;
   cout << ucB.EvalStr("val") << endl;
   cout << ucC.EvalStr("val") << endl;
}
				
			
original default
uc
ucB
ucC
Undefined identifier
uc
ucB
ucC
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      uCalc.DefaultInstance.DefineVariable("val = 'original default'")
      Console.WriteLine(uCalc.DefaultInstance.EvalStr("val"))
      
      uc.DefineVariable("val = 'uc'")
      uc.IsDefault = true
      Console.WriteLine(uCalc.DefaultInstance.EvalStr("val"))
      
      Dim ucB As New uCalc()
      ucB.DefineVariable("val = 'ucB'")
      ucB.IsDefault = true
      Console.WriteLine(uCalc.DefaultInstance.EvalStr("val"))
      
      Dim ucC As New uCalc()
      ucC.DefineVariable("val = 'ucC'")
      ucC.IsDefault = true
      Console.WriteLine(uCalc.DefaultInstance.EvalStr("val"))
      
      uCalc.DefaultClear()
      
      '// The original unnamed default instance is reset so user variable val no longer exists
      Console.WriteLine(uCalc.DefaultInstance.EvalStr("val"))
      
      '// The other instances are removed from Default list but remain active
      Console.WriteLine(uc.EvalStr("val"))
      Console.WriteLine(ucB.EvalStr("val"))
      Console.WriteLine(ucC.EvalStr("val"))
   End Sub
End Module
				
			
original default
uc
ucB
ucC
Undefined identifier
uc
ucB
ucC
Defining uCalc Strings and Expressions in the default uCalc object space
				
					using uCalcSoftware;

var uc = new uCalc();
var ucB = new uCalc();

uc.DefineVariable("x = 111");
ucB.DefineVariable("x = 222");

Console.WriteLine("--- using 'uc' as default ---");
uc.IsDefault = true;

uCalc.String MyString = "The variable value is: x";
Console.WriteLine(MyString.Replace("x", "{@Eval: x}"));

uCalc.Expression MyExpression = "x * 1000";
Console.WriteLine(MyExpression.Evaluate());

var MyTransformer = new uCalc.Transformer();
MyTransformer.Text = "Value is: x";
MyTransformer.FromTo("x", "{@Eval: x}");
Console.WriteLine(MyTransformer.Transform());


Console.WriteLine("--- using 'ucB' as default ---");
ucB.IsDefault = true;

uCalc.String MyStringB = "The variable value is: x";
Console.WriteLine(MyStringB.Replace("x", "{@Eval: x}"));

uCalc.Expression MyExpressionB = "x * 1000";
Console.WriteLine(MyExpressionB.Evaluate());

var MyTransformerB = new uCalc.Transformer();
MyTransformerB.Str("Value is: x");
MyTransformerB.FromTo("x", "{@Eval: x}");
Console.WriteLine(MyTransformerB.Transform());

				
			
--- using 'uc' as default ---
The variable value is: 111
111000
Value is: 111
--- using 'ucB' as default ---
The variable value is: 222
222000
Value is: 222
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   uCalc ucB;

   uc.DefineVariable("x = 111");
   ucB.DefineVariable("x = 222");

   cout << "--- using 'uc' as default ---" << endl;
   uc.IsDefault(true);

   uCalc::String MyString = "The variable value is: x";
   cout << MyString.Replace("x", "{@Eval: x}") << endl;

   uCalc::Expression MyExpression = "x * 1000";
   cout << MyExpression.Evaluate() << endl;

   uCalc::Transformer MyTransformer;
   MyTransformer.Text("Value is: x");
   MyTransformer.FromTo("x", "{@Eval: x}");
   cout << MyTransformer.Transform() << endl;


   cout << "--- using 'ucB' as default ---" << endl;
   ucB.IsDefault(true);

   uCalc::String MyStringB = "The variable value is: x";
   cout << MyStringB.Replace("x", "{@Eval: x}") << endl;

   uCalc::Expression MyExpressionB = "x * 1000";
   cout << MyExpressionB.Evaluate() << endl;

   uCalc::Transformer MyTransformerB;
   MyTransformerB.Str("Value is: x");
   MyTransformerB.FromTo("x", "{@Eval: x}");
   cout << MyTransformerB.Transform() << endl;

}
				
			
--- using 'uc' as default ---
The variable value is: 111
111000
Value is: 111
--- using 'ucB' as default ---
The variable value is: 222
222000
Value is: 222
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      Dim ucB As New uCalc()
      
      uc.DefineVariable("x = 111")
      ucB.DefineVariable("x = 222")
      
      Console.WriteLine("--- using 'uc' as default ---")
      uc.IsDefault = true
      
      Dim MyString As uCalc.String = "The variable value is: x"
      Console.WriteLine(MyString.Replace("x", "{@Eval: x}"))
      
      Dim MyExpression As uCalc.Expression = "x * 1000"
      Console.WriteLine(MyExpression.Evaluate())
      
      Dim MyTransformer As New uCalc.Transformer()
      MyTransformer.Text = "Value is: x"
      MyTransformer.FromTo("x", "{@Eval: x}")
      Console.WriteLine(MyTransformer.Transform())
      
      
      Console.WriteLine("--- using 'ucB' as default ---")
      ucB.IsDefault = true
      
      Dim MyStringB As uCalc.String = "The variable value is: x"
      Console.WriteLine(MyStringB.Replace("x", "{@Eval: x}"))
      
      Dim MyExpressionB As uCalc.Expression = "x * 1000"
      Console.WriteLine(MyExpressionB.Evaluate())
      
      Dim MyTransformerB As New uCalc.Transformer()
      MyTransformerB.Str("Value is: x")
      MyTransformerB.FromTo("x", "{@Eval: x}")
      Console.WriteLine(MyTransformerB.Transform())
      
   End Sub
End Module
				
			
--- using 'uc' as default ---
The variable value is: 111
111000
Value is: 111
--- using 'ucB' as default ---
The variable value is: 222
222000
Value is: 222