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.
An overview of how uCalc manages state, isolation, and context through instances, the default instance stack, and hierarchical parsing.
The uCalc engine is not a collection of static functions; it is a stateful, object-oriented system. Understanding how it manages state, scope, and context is crucial for building robust, scalable, and memory-safe applications. This topic provides a high-level overview of the core architectural concepts that govern the uCalc environment.
Mastering these concepts will allow you to leverage the full power of the library, from creating isolated sandboxes for parallel processing to building sophisticated, multi-layered parsers.
uCalc Instance: An Isolated SandboxEach instance of the uCalc class is a self-contained "world." It maintains its own isolated symbol table, which includes all defined variables, functions, and operators.
This instance-based architecture ensures that different parser configurations do not interfere with each other, making it ideal for applications with plugins or multiple concurrent tasks. For details on managing the memory of these instances, see the Managing Parser Instances & Lifetime tutorial.
For convenience, uCalc provides a globally accessible context via the static DefaultInstance property. However, this is not a single, rigid global object; it is a LIFO (Last-In, First-Out) stack.
uCalc instance onto the stack using IsDefault(true), making it the new "ambient" context.IsDefault(false)), the previous default instance is automatically restored.This provides the benefits of a global singleton without the rigidity, enabling temporary, scoped overrides for different parts of an application.
uCalc instance is not thread-safe. Do not share one instance across multiple threads without external locking (which is an anti-pattern).Clone() method.For a detailed explanation, see the Thread safety topic.
In addition to instance-level isolation, uCalc provides two powerful mechanisms for managing nested scopes within a single operation.
LocalTransformer)A Rule can have its own LocalTransformer, which is a nested Transformer that operates only on the text matched by its parent rule. This is the primary mechanism for hierarchical parsing of structured languages like HTML or XML. See the Hierarchical Parsing (LocalTransformer) topic for more details.
The uCalc.String class uses "live views." Methods like After(), Before(), and Between() return new uCalc.String objects that are modifiable windows into the parent. Any change to a child view directly affects the parent, enabling powerful, in-place editing of sub-sections. See Chaining Fluent Operations.
uCalc's state and context management model provides distinct advantages over common paradigms:
LocalTransformer and live views automate complex scoping and coordinate-mapping tasks that would require verbose, error-prone manual implementation with standard string and regex libraries.