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.
Count = [Int64]
Property
Product:
Class:
Gets the number of sub-elements for an item, such as function parameters, array elements, or operator operands.
Remarks
The Count() method is a versatile introspection tool that returns the number of constituent parts for a given uCalc.Item. Its meaning is context-dependent and changes based on the type of the item being queried.
This is essential for runtime logic that needs to understand the structure of functions, arrays, and other defined symbols.
Behavior by Item Type
The value returned by Count() corresponds to a different concept for each item type:
| Item Type | Count() Returns | Example |
|---|---|---|
| Array | The number of elements. | An array defined as MyArray[10] returns 10. |
| Function | The number of declared parameters. | A function f(x, y, z=5) returns 3. |
| Operator | The number of operands. | An infix operator like + returns 2; a prefix operator like - returns 1. |
Transformer Rule | The number of distinct parts in its pattern. | A rule for Start {a} {b} End returns 4. |
| Token | The number of sub-tokens in a compound token. | A custom token composed of multiple parts. |
⚠️ Special Cases
Variadic Functions: For functions that accept a variable number of arguments (defined with
...),Count()returns -1 (or the maximum value for an unsigned integer, likeSIZE_MAX). This indicates an indeterminate number of parameters. You should check for this special value in your code.Complex Rules: For a Transformer Rule, the count can be non-obvious, especially with nested optional (
[]) or alternative (|) parts. The count generally reflects the number of top-level components in the pattern definition string.
💡 Comparative Analysis
Item.Count() provides a unified interface for functionality that is often spread across different properties or methods in other languages.
vs. C#: In C#, you would use
.Lengthfor arrays,.GetParameters().Lengthfor method reflection, and.Count()for collections. uCalc consolidates these concepts into a single.Count()method on the versatileItemobject.vs. C++: In C++, you might use
std::size()for containers or template metaprogramming to get function arity. uCalc's method is a dynamic, runtime equivalent that operates on symbols defined within its engine, providing a simpler and more consistent approach to introspection.
Examples
A succinct demonstration of retrieving the element count of an array and the parameter count of a function.
using uCalcSoftware;
var uc = new uCalc();
var MyArray = uc.DefineVariable("MyArray[10] As Int");
var MyFunc = uc.DefineFunction("MyFunc(a, b, c) = a+b+c");
Console.WriteLine($"Array element count: {MyArray.Count}");
Console.WriteLine($"Function parameter count: {MyFunc.Count}");
Array element count: 10
Function parameter count: 3 using uCalcSoftware; var uc = new uCalc(); var MyArray = uc.DefineVariable("MyArray[10] As Int"); var MyFunc = uc.DefineFunction("MyFunc(a, b, c) = a+b+c"); Console.WriteLine($"Array element count: {MyArray.Count}"); Console.WriteLine($"Function parameter count: {MyFunc.Count}");
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
auto MyArray = uc.DefineVariable("MyArray[10] As Int");
auto MyFunc = uc.DefineFunction("MyFunc(a, b, c) = a+b+c");
cout << "Array element count: " << MyArray.Count() << endl;
cout << "Function parameter count: " << MyFunc.Count() << endl;
}
Array element count: 10
Function parameter count: 3 #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; auto MyArray = uc.DefineVariable("MyArray[10] As Int"); auto MyFunc = uc.DefineFunction("MyFunc(a, b, c) = a+b+c"); cout << "Array element count: " << MyArray.Count() << endl; cout << "Function parameter count: " << MyFunc.Count() << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Dim MyArray = uc.DefineVariable("MyArray[10] As Int")
Dim MyFunc = uc.DefineFunction("MyFunc(a, b, c) = a+b+c")
Console.WriteLine($"Array element count: {MyArray.Count}")
Console.WriteLine($"Function parameter count: {MyFunc.Count}")
End Sub
End Module
Array element count: 10
Function parameter count: 3 Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() Dim MyArray = uc.DefineVariable("MyArray[10] As Int") Dim MyFunc = uc.DefineFunction("MyFunc(a, b, c) = a+b+c") Console.WriteLine($"Array element count: {MyArray.Count}") Console.WriteLine($"Function parameter count: {MyFunc.Count}") End Sub End Module
Comprehensive demonstration of Count() across arrays, functions with different parameter types, and operators.
using uCalcSoftware;
var uc = new uCalc();
static void MyAverage(uCalc.Callback cb) {
double Total = 0;
for (int x = 1; x <= cb.ArgCount(); x++) {
Total = Total + cb.Arg(x);
}
cb.Return(Total / cb.ArgCount());
}
var MyArrayA = uc.DefineVariable("MyArrayA[] = {10, 20, 30, 40, 50}");
var MyArrayB = uc.DefineVariable("MyArrayB[15]");
var FunctionA = uc.DefineFunction("FuncA(x, y, z) = x + y + z");
var FunctionB = uc.DefineFunction("FuncB(x, y, a = 12, b = 34) = x+y+a+b");
var FunctionC = uc.DefineFunction("FuncC(x, y ...)", MyAverage);
var FunctionD = uc.DefineFunction("FuncD() = 1+1");
Console.WriteLine($"Elements in array (from initializer): {MyArrayA.Count}");
Console.WriteLine($"Elements in array (from size): {MyArrayB.Count}");
Console.WriteLine($"Parameters in FuncA() (fixed): {FunctionA.Count}");
Console.WriteLine($"Parameters in FuncB() (with optional): {FunctionB.Count}");
Console.WriteLine($"Parameters in FuncC() (variadic): {FunctionC.Count}");
Console.WriteLine($"Parameters in FuncD() (none): {FunctionD.Count}");
Console.WriteLine($"Operands in '!' operator (postfix): {uc.ItemOf("!").Count}");
Console.WriteLine($"Operands in '>' operator (infix): {uc.ItemOf(">").Count}");
Elements in array (from initializer): 5
Elements in array (from size): 15
Parameters in FuncA() (fixed): 3
Parameters in FuncB() (with optional): 4
Parameters in FuncC() (variadic): -1
Parameters in FuncD() (none): 0
Operands in '!' operator (postfix): 1
Operands in '>' operator (infix): 2 using uCalcSoftware; var uc = new uCalc(); static void MyAverage(uCalc.Callback cb) { double Total = 0; for (int x = 1; x <= cb.ArgCount(); x++) { Total = Total + cb.Arg(x); } cb.Return(Total / cb.ArgCount()); } var MyArrayA = uc.DefineVariable("MyArrayA[] = {10, 20, 30, 40, 50}"); var MyArrayB = uc.DefineVariable("MyArrayB[15]"); var FunctionA = uc.DefineFunction("FuncA(x, y, z) = x + y + z"); var FunctionB = uc.DefineFunction("FuncB(x, y, a = 12, b = 34) = x+y+a+b"); var FunctionC = uc.DefineFunction("FuncC(x, y ...)", MyAverage); var FunctionD = uc.DefineFunction("FuncD() = 1+1"); Console.WriteLine($"Elements in array (from initializer): {MyArrayA.Count}"); Console.WriteLine($"Elements in array (from size): {MyArrayB.Count}"); Console.WriteLine($"Parameters in FuncA() (fixed): {FunctionA.Count}"); Console.WriteLine($"Parameters in FuncB() (with optional): {FunctionB.Count}"); Console.WriteLine($"Parameters in FuncC() (variadic): {FunctionC.Count}"); Console.WriteLine($"Parameters in FuncD() (none): {FunctionD.Count}"); Console.WriteLine($"Operands in '!' operator (postfix): {uc.ItemOf("!").Count}"); Console.WriteLine($"Operands in '>' operator (infix): {uc.ItemOf(">").Count}");
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
void ucalc_call MyAverage(uCalcBase::Callback cb) {
double Total = 0;
for (int x = 1; x <= cb.ArgCount(); x++) {
Total = Total + cb.Arg(x);
}
cb.Return(Total / cb.ArgCount());
}
int main() {
uCalc uc;
auto MyArrayA = uc.DefineVariable("MyArrayA[] = {10, 20, 30, 40, 50}");
auto MyArrayB = uc.DefineVariable("MyArrayB[15]");
auto FunctionA = uc.DefineFunction("FuncA(x, y, z) = x + y + z");
auto FunctionB = uc.DefineFunction("FuncB(x, y, a = 12, b = 34) = x+y+a+b");
auto FunctionC = uc.DefineFunction("FuncC(x, y ...)", MyAverage);
auto FunctionD = uc.DefineFunction("FuncD() = 1+1");
cout << "Elements in array (from initializer): " << MyArrayA.Count() << endl;
cout << "Elements in array (from size): " << MyArrayB.Count() << endl;
cout << "Parameters in FuncA() (fixed): " << FunctionA.Count() << endl;
cout << "Parameters in FuncB() (with optional): " << FunctionB.Count() << endl;
cout << "Parameters in FuncC() (variadic): " << FunctionC.Count() << endl;
cout << "Parameters in FuncD() (none): " << FunctionD.Count() << endl;
cout << "Operands in '!' operator (postfix): " << uc.ItemOf("!").Count() << endl;
cout << "Operands in '>' operator (infix): " << uc.ItemOf(">").Count() << endl;
}
Elements in array (from initializer): 5
Elements in array (from size): 15
Parameters in FuncA() (fixed): 3
Parameters in FuncB() (with optional): 4
Parameters in FuncC() (variadic): -1
Parameters in FuncD() (none): 0
Operands in '!' operator (postfix): 1
Operands in '>' operator (infix): 2 #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; void ucalc_call MyAverage(uCalcBase::Callback cb) { double Total = 0; for (int x = 1; x <= cb.ArgCount(); x++) { Total = Total + cb.Arg(x); } cb.Return(Total / cb.ArgCount()); } int main() { uCalc uc; auto MyArrayA = uc.DefineVariable("MyArrayA[] = {10, 20, 30, 40, 50}"); auto MyArrayB = uc.DefineVariable("MyArrayB[15]"); auto FunctionA = uc.DefineFunction("FuncA(x, y, z) = x + y + z"); auto FunctionB = uc.DefineFunction("FuncB(x, y, a = 12, b = 34) = x+y+a+b"); auto FunctionC = uc.DefineFunction("FuncC(x, y ...)", MyAverage); auto FunctionD = uc.DefineFunction("FuncD() = 1+1"); cout << "Elements in array (from initializer): " << MyArrayA.Count() << endl; cout << "Elements in array (from size): " << MyArrayB.Count() << endl; cout << "Parameters in FuncA() (fixed): " << FunctionA.Count() << endl; cout << "Parameters in FuncB() (with optional): " << FunctionB.Count() << endl; cout << "Parameters in FuncC() (variadic): " << FunctionC.Count() << endl; cout << "Parameters in FuncD() (none): " << FunctionD.Count() << endl; cout << "Operands in '!' operator (postfix): " << uc.ItemOf("!").Count() << endl; cout << "Operands in '>' operator (infix): " << uc.ItemOf(">").Count() << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub MyAverage(ByVal cb As uCalc.Callback)
Dim Total As Double = 0
For x As Integer = 1 To cb.ArgCount()
Total = Total + cb.Arg(x)
Next
cb.Return(Total / cb.ArgCount())
End Sub
Public Sub Main()
Dim uc As New uCalc()
Dim MyArrayA = uc.DefineVariable("MyArrayA[] = {10, 20, 30, 40, 50}")
Dim MyArrayB = uc.DefineVariable("MyArrayB[15]")
Dim FunctionA = uc.DefineFunction("FuncA(x, y, z) = x + y + z")
Dim FunctionB = uc.DefineFunction("FuncB(x, y, a = 12, b = 34) = x+y+a+b")
Dim FunctionC = uc.DefineFunction("FuncC(x, y ...)", AddressOf MyAverage)
Dim FunctionD = uc.DefineFunction("FuncD() = 1+1")
Console.WriteLine($"Elements in array (from initializer): {MyArrayA.Count}")
Console.WriteLine($"Elements in array (from size): {MyArrayB.Count}")
Console.WriteLine($"Parameters in FuncA() (fixed): {FunctionA.Count}")
Console.WriteLine($"Parameters in FuncB() (with optional): {FunctionB.Count}")
Console.WriteLine($"Parameters in FuncC() (variadic): {FunctionC.Count}")
Console.WriteLine($"Parameters in FuncD() (none): {FunctionD.Count}")
Console.WriteLine($"Operands in '!' operator (postfix): {uc.ItemOf("!").Count}")
Console.WriteLine($"Operands in '>' operator (infix): {uc.ItemOf(">").Count}")
End Sub
End Module
Elements in array (from initializer): 5
Elements in array (from size): 15
Parameters in FuncA() (fixed): 3
Parameters in FuncB() (with optional): 4
Parameters in FuncC() (variadic): -1
Parameters in FuncD() (none): 0
Operands in '!' operator (postfix): 1
Operands in '>' operator (infix): 2 Imports System Imports uCalcSoftware Public Module Program Public Sub MyAverage(ByVal cb As uCalc.Callback) Dim Total As Double = 0 For x As Integer = 1 To cb.ArgCount() Total = Total + cb.Arg(x) Next cb.Return(Total / cb.ArgCount()) End Sub Public Sub Main() Dim uc As New uCalc() Dim MyArrayA = uc.DefineVariable("MyArrayA[] = {10, 20, 30, 40, 50}") Dim MyArrayB = uc.DefineVariable("MyArrayB[15]") Dim FunctionA = uc.DefineFunction("FuncA(x, y, z) = x + y + z") Dim FunctionB = uc.DefineFunction("FuncB(x, y, a = 12, b = 34) = x+y+a+b") Dim FunctionC = uc.DefineFunction("FuncC(x, y ...)", AddressOf MyAverage) Dim FunctionD = uc.DefineFunction("FuncD() = 1+1") Console.WriteLine($"Elements in array (from initializer): {MyArrayA.Count}") Console.WriteLine($"Elements in array (from size): {MyArrayB.Count}") Console.WriteLine($"Parameters in FuncA() (fixed): {FunctionA.Count}") Console.WriteLine($"Parameters in FuncB() (with optional): {FunctionB.Count}") Console.WriteLine($"Parameters in FuncC() (variadic): {FunctionC.Count}") Console.WriteLine($"Parameters in FuncD() (none): {FunctionD.Count}") Console.WriteLine($"Operands in '!' operator (postfix): {uc.ItemOf("!").Count}") Console.WriteLine($"Operands in '>' operator (infix): {uc.ItemOf(">").Count}") End Sub End Module
Using Properties with ItemOf to disambiguate between the infix and prefix versions of the '-' operator.
using uCalcSoftware;
var uc = new uCalc();
var infix_minus = uc.ItemOf("-", uCalc.Properties(ItemIs.Infix));
var prefix_minus = uc.ItemOf("-", uCalc.Properties(ItemIs.Prefix));
Console.WriteLine($"Operands for infix '-': {infix_minus.Count}");
Console.WriteLine($"Operands for prefix '-': {prefix_minus.Count}");
Operands for infix '-': 2
Operands for prefix '-': 1 using uCalcSoftware; var uc = new uCalc(); var infix_minus = uc.ItemOf("-", uCalc.Properties(ItemIs.Infix)); var prefix_minus = uc.ItemOf("-", uCalc.Properties(ItemIs.Prefix)); Console.WriteLine($"Operands for infix '-': {infix_minus.Count}"); Console.WriteLine($"Operands for prefix '-': {prefix_minus.Count}");
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
auto infix_minus = uc.ItemOf("-", uCalc::Properties(ItemIs::Infix));
auto prefix_minus = uc.ItemOf("-", uCalc::Properties(ItemIs::Prefix));
cout << "Operands for infix '-': " << infix_minus.Count() << endl;
cout << "Operands for prefix '-': " << prefix_minus.Count() << endl;
}
Operands for infix '-': 2
Operands for prefix '-': 1 #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; auto infix_minus = uc.ItemOf("-", uCalc::Properties(ItemIs::Infix)); auto prefix_minus = uc.ItemOf("-", uCalc::Properties(ItemIs::Prefix)); cout << "Operands for infix '-': " << infix_minus.Count() << endl; cout << "Operands for prefix '-': " << prefix_minus.Count() << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Dim infix_minus = uc.ItemOf("-", uCalc.Properties(ItemIs.Infix))
Dim prefix_minus = uc.ItemOf("-", uCalc.Properties(ItemIs.Prefix))
Console.WriteLine($"Operands for infix '-': {infix_minus.Count}")
Console.WriteLine($"Operands for prefix '-': {prefix_minus.Count}")
End Sub
End Module
Operands for infix '-': 2
Operands for prefix '-': 1 Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() Dim infix_minus = uc.ItemOf("-", uCalc.Properties(ItemIs.Infix)) Dim prefix_minus = uc.ItemOf("-", uCalc.Properties(ItemIs.Prefix)) Console.WriteLine($"Operands for infix '-': {infix_minus.Count}") Console.WriteLine($"Operands for prefix '-': {prefix_minus.Count}") End Sub End Module
Demonstrates introspection within a callback, retrieving the parameter count of the calling function.
using uCalcSoftware;
var uc = new uCalc();
static void ItemCallback(uCalc.Callback cb) {
Console.WriteLine($"Function '{cb.Item.Name}' was called.");
Console.WriteLine($"It is defined with {cb.Item.Count} parameters.");
}
uc.DefineFunction("MyFunc(x, y) As Double", ItemCallback);
uc.EvalStr("MyFunc(1, 2)");
Function 'myfunc' was called.
It is defined with 2 parameters. using uCalcSoftware; var uc = new uCalc(); static void ItemCallback(uCalc.Callback cb) { Console.WriteLine($"Function '{cb.Item.Name}' was called."); Console.WriteLine($"It is defined with {cb.Item.Count} parameters."); } uc.DefineFunction("MyFunc(x, y) As Double", ItemCallback); uc.EvalStr("MyFunc(1, 2)");
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
void ucalc_call ItemCallback(uCalcBase::Callback cb) {
cout << "Function '" << cb.Item().Name() << "' was called." << endl;
cout << "It is defined with " << cb.Item().Count() << " parameters." << endl;
}
int main() {
uCalc uc;
uc.DefineFunction("MyFunc(x, y) As Double", ItemCallback);
uc.EvalStr("MyFunc(1, 2)");
}
Function 'myfunc' was called.
It is defined with 2 parameters. #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; void ucalc_call ItemCallback(uCalcBase::Callback cb) { cout << "Function '" << cb.Item().Name() << "' was called." << endl; cout << "It is defined with " << cb.Item().Count() << " parameters." << endl; } int main() { uCalc uc; uc.DefineFunction("MyFunc(x, y) As Double", ItemCallback); uc.EvalStr("MyFunc(1, 2)"); }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub ItemCallback(ByVal cb As uCalc.Callback)
Console.WriteLine($"Function '{cb.Item.Name}' was called.")
Console.WriteLine($"It is defined with {cb.Item.Count} parameters.")
End Sub
Public Sub Main()
Dim uc As New uCalc()
uc.DefineFunction("MyFunc(x, y) As Double", AddressOf ItemCallback)
uc.EvalStr("MyFunc(1, 2)")
End Sub
End Module
Function 'myfunc' was called.
It is defined with 2 parameters. Imports System Imports uCalcSoftware Public Module Program Public Sub ItemCallback(ByVal cb As uCalc.Callback) Console.WriteLine($"Function '{cb.Item.Name}' was called.") Console.WriteLine($"It is defined with {cb.Item.Count} parameters.") End Sub Public Sub Main() Dim uc As New uCalc() uc.DefineFunction("MyFunc(x, y) As Double", AddressOf ItemCallback) uc.EvalStr("MyFunc(1, 2)") End Sub End Module
ItemOf selection between infix version of - (minus) operator and unary prefix version with Properties
using uCalcSoftware;
var uc = new uCalc();
// Returns number of operands for the given operators
Console.WriteLine(uc.ItemOf("-", uCalc.Properties(ItemIs.Infix)).Count);
Console.WriteLine(uc.ItemOf("-", uCalc.Properties(ItemIs.Prefix)).Count);
// You can pass one property directly in C++ and C#, but not VB
Console.WriteLine(uc.ItemOf("-", ItemIs.Infix).Count);
Console.WriteLine(uc.ItemOf("-", ItemIs.Prefix).Count);
2
1
2
1 using uCalcSoftware; var uc = new uCalc(); // Returns number of operands for the given operators Console.WriteLine(uc.ItemOf("-", uCalc.Properties(ItemIs.Infix)).Count); Console.WriteLine(uc.ItemOf("-", uCalc.Properties(ItemIs.Prefix)).Count); // You can pass one property directly in C++ and C#, but not VB Console.WriteLine(uc.ItemOf("-", ItemIs.Infix).Count); Console.WriteLine(uc.ItemOf("-", ItemIs.Prefix).Count);
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
// Returns number of operands for the given operators
cout << uc.ItemOf("-", uCalc::Properties(ItemIs::Infix)).Count() << endl;
cout << uc.ItemOf("-", uCalc::Properties(ItemIs::Prefix)).Count() << endl;
// You can pass one property directly in C++ and C#, but not VB
cout << uc.ItemOf("-", ItemIs::Infix).Count() << endl;
cout << uc.ItemOf("-", ItemIs::Prefix).Count() << endl;
}
2
1
2
1 #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; // Returns number of operands for the given operators cout << uc.ItemOf("-", uCalc::Properties(ItemIs::Infix)).Count() << endl; cout << uc.ItemOf("-", uCalc::Properties(ItemIs::Prefix)).Count() << endl; // You can pass one property directly in C++ and C#, but not VB cout << uc.ItemOf("-", ItemIs::Infix).Count() << endl; cout << uc.ItemOf("-", ItemIs::Prefix).Count() << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
'// Returns number of operands for the given operators
Console.WriteLine(uc.ItemOf("-", uCalc.Properties(ItemIs.Infix)).Count)
Console.WriteLine(uc.ItemOf("-", uCalc.Properties(ItemIs.Prefix)).Count)
'// You can pass one property directly in C++ and C#, but not VB
Console.WriteLine(2) '// C++ and C# only: uc.ItemOf("-", ItemIs::Infix).@Count();
Console.WriteLine(1) '// C++ and C# only: uc.ItemOf("-", ItemIs::Prefix).@Count();
End Sub
End Module
2
1
2
1 Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() '// Returns number of operands for the given operators Console.WriteLine(uc.ItemOf("-", uCalc.Properties(ItemIs.Infix)).Count) Console.WriteLine(uc.ItemOf("-", uCalc.Properties(ItemIs.Prefix)).Count) '// You can pass one property directly in C++ and C#, but not VB Console.WriteLine(2) '// C++ and C# only: uc.ItemOf("-", ItemIs::Infix).@Count(); Console.WriteLine(1) '// C++ and C# only: uc.ItemOf("-", ItemIs::Prefix).@Count(); End Sub End Module
Dispaying the number of elements in an array
using uCalcSoftware;
var uc = new uCalc();
static void MyAverage(uCalc.Callback cb) {
double Total = 0;
for (int x = 1; x <= cb.ArgCount(); x++) {
Total = Total + cb.Arg(x);
}
cb.Return(Total / cb.ArgCount());
}
var MyArrayA = uc.DefineVariable("MyArrayA[] = {10, 20, 30, 40, 50}");
var MyArrayB = uc.DefineVariable("MyArrayB[15]");
var FunctionA = uc.DefineFunction("FuncA(x, y, z) = x + y + z");
var FunctionB = uc.DefineFunction("FuncB(x, y, a = 12, b = 34) = x+y+a+b");
var FunctionC = uc.DefineFunction("FuncC(x, y ...)", MyAverage);
var FunctionD = uc.DefineFunction("FuncD() = 1+1");
Console.WriteLine($"Elements in MyArrayA: {MyArrayA.Count}");
Console.WriteLine($"Elements in MyArrayB: {MyArrayB.Count}");
Console.WriteLine($"Params in FuncA(): {FunctionA.Count}");
Console.WriteLine($"Params in FuncB(): {FunctionB.Count}");
Console.WriteLine($"Params in FuncC(): {FunctionC.Count}"); // -1 or 2^n-1 (n=32 or 64)
Console.WriteLine($"Params in FuncD(): {FunctionD.Count}");
Console.WriteLine($"Operands in ! operator: {uc.ItemOf("!").Count}");
Console.WriteLine($"Operands in > operator: {uc.ItemOf(">").Count}");
Elements in MyArrayA: 5
Elements in MyArrayB: 15
Params in FuncA(): 3
Params in FuncB(): 4
Params in FuncC(): -1
Params in FuncD(): 0
Operands in ! operator: 1
Operands in > operator: 2 using uCalcSoftware; var uc = new uCalc(); static void MyAverage(uCalc.Callback cb) { double Total = 0; for (int x = 1; x <= cb.ArgCount(); x++) { Total = Total + cb.Arg(x); } cb.Return(Total / cb.ArgCount()); } var MyArrayA = uc.DefineVariable("MyArrayA[] = {10, 20, 30, 40, 50}"); var MyArrayB = uc.DefineVariable("MyArrayB[15]"); var FunctionA = uc.DefineFunction("FuncA(x, y, z) = x + y + z"); var FunctionB = uc.DefineFunction("FuncB(x, y, a = 12, b = 34) = x+y+a+b"); var FunctionC = uc.DefineFunction("FuncC(x, y ...)", MyAverage); var FunctionD = uc.DefineFunction("FuncD() = 1+1"); Console.WriteLine($"Elements in MyArrayA: {MyArrayA.Count}"); Console.WriteLine($"Elements in MyArrayB: {MyArrayB.Count}"); Console.WriteLine($"Params in FuncA(): {FunctionA.Count}"); Console.WriteLine($"Params in FuncB(): {FunctionB.Count}"); Console.WriteLine($"Params in FuncC(): {FunctionC.Count}"); // -1 or 2^n-1 (n=32 or 64) Console.WriteLine($"Params in FuncD(): {FunctionD.Count}"); Console.WriteLine($"Operands in ! operator: {uc.ItemOf("!").Count}"); Console.WriteLine($"Operands in > operator: {uc.ItemOf(">").Count}");
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
void ucalc_call MyAverage(uCalcBase::Callback cb) {
double Total = 0;
for (int x = 1; x <= cb.ArgCount(); x++) {
Total = Total + cb.Arg(x);
}
cb.Return(Total / cb.ArgCount());
}
int main() {
uCalc uc;
auto MyArrayA = uc.DefineVariable("MyArrayA[] = {10, 20, 30, 40, 50}");
auto MyArrayB = uc.DefineVariable("MyArrayB[15]");
auto FunctionA = uc.DefineFunction("FuncA(x, y, z) = x + y + z");
auto FunctionB = uc.DefineFunction("FuncB(x, y, a = 12, b = 34) = x+y+a+b");
auto FunctionC = uc.DefineFunction("FuncC(x, y ...)", MyAverage);
auto FunctionD = uc.DefineFunction("FuncD() = 1+1");
cout << "Elements in MyArrayA: " << MyArrayA.Count() << endl;
cout << "Elements in MyArrayB: " << MyArrayB.Count() << endl;
cout << "Params in FuncA(): " << FunctionA.Count() << endl;
cout << "Params in FuncB(): " << FunctionB.Count() << endl;
cout << "Params in FuncC(): " << FunctionC.Count() << endl; // -1 or 2^n-1 (n=32 or 64)
cout << "Params in FuncD(): " << FunctionD.Count() << endl;
cout << "Operands in ! operator: " << uc.ItemOf("!").Count() << endl;
cout << "Operands in > operator: " << uc.ItemOf(">").Count() << endl;
}
Elements in MyArrayA: 5
Elements in MyArrayB: 15
Params in FuncA(): 3
Params in FuncB(): 4
Params in FuncC(): -1
Params in FuncD(): 0
Operands in ! operator: 1
Operands in > operator: 2 #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; void ucalc_call MyAverage(uCalcBase::Callback cb) { double Total = 0; for (int x = 1; x <= cb.ArgCount(); x++) { Total = Total + cb.Arg(x); } cb.Return(Total / cb.ArgCount()); } int main() { uCalc uc; auto MyArrayA = uc.DefineVariable("MyArrayA[] = {10, 20, 30, 40, 50}"); auto MyArrayB = uc.DefineVariable("MyArrayB[15]"); auto FunctionA = uc.DefineFunction("FuncA(x, y, z) = x + y + z"); auto FunctionB = uc.DefineFunction("FuncB(x, y, a = 12, b = 34) = x+y+a+b"); auto FunctionC = uc.DefineFunction("FuncC(x, y ...)", MyAverage); auto FunctionD = uc.DefineFunction("FuncD() = 1+1"); cout << "Elements in MyArrayA: " << MyArrayA.Count() << endl; cout << "Elements in MyArrayB: " << MyArrayB.Count() << endl; cout << "Params in FuncA(): " << FunctionA.Count() << endl; cout << "Params in FuncB(): " << FunctionB.Count() << endl; cout << "Params in FuncC(): " << FunctionC.Count() << endl; // -1 or 2^n-1 (n=32 or 64) cout << "Params in FuncD(): " << FunctionD.Count() << endl; cout << "Operands in ! operator: " << uc.ItemOf("!").Count() << endl; cout << "Operands in > operator: " << uc.ItemOf(">").Count() << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub MyAverage(ByVal cb As uCalc.Callback)
Dim Total As Double = 0
For x As Integer = 1 To cb.ArgCount()
Total = Total + cb.Arg(x)
Next
cb.Return(Total / cb.ArgCount())
End Sub
Public Sub Main()
Dim uc As New uCalc()
Dim MyArrayA = uc.DefineVariable("MyArrayA[] = {10, 20, 30, 40, 50}")
Dim MyArrayB = uc.DefineVariable("MyArrayB[15]")
Dim FunctionA = uc.DefineFunction("FuncA(x, y, z) = x + y + z")
Dim FunctionB = uc.DefineFunction("FuncB(x, y, a = 12, b = 34) = x+y+a+b")
Dim FunctionC = uc.DefineFunction("FuncC(x, y ...)", AddressOf MyAverage)
Dim FunctionD = uc.DefineFunction("FuncD() = 1+1")
Console.WriteLine($"Elements in MyArrayA: {MyArrayA.Count}")
Console.WriteLine($"Elements in MyArrayB: {MyArrayB.Count}")
Console.WriteLine($"Params in FuncA(): {FunctionA.Count}")
Console.WriteLine($"Params in FuncB(): {FunctionB.Count}")
Console.WriteLine($"Params in FuncC(): {FunctionC.Count}") '// -1 or 2^n-1 (n=32 or 64)
Console.WriteLine($"Params in FuncD(): {FunctionD.Count}")
Console.WriteLine($"Operands in ! operator: {uc.ItemOf("!").Count}")
Console.WriteLine($"Operands in > operator: {uc.ItemOf(">").Count}")
End Sub
End Module
Elements in MyArrayA: 5
Elements in MyArrayB: 15
Params in FuncA(): 3
Params in FuncB(): 4
Params in FuncC(): -1
Params in FuncD(): 0
Operands in ! operator: 1
Operands in > operator: 2 Imports System Imports uCalcSoftware Public Module Program Public Sub MyAverage(ByVal cb As uCalc.Callback) Dim Total As Double = 0 For x As Integer = 1 To cb.ArgCount() Total = Total + cb.Arg(x) Next cb.Return(Total / cb.ArgCount()) End Sub Public Sub Main() Dim uc As New uCalc() Dim MyArrayA = uc.DefineVariable("MyArrayA[] = {10, 20, 30, 40, 50}") Dim MyArrayB = uc.DefineVariable("MyArrayB[15]") Dim FunctionA = uc.DefineFunction("FuncA(x, y, z) = x + y + z") Dim FunctionB = uc.DefineFunction("FuncB(x, y, a = 12, b = 34) = x+y+a+b") Dim FunctionC = uc.DefineFunction("FuncC(x, y ...)", AddressOf MyAverage) Dim FunctionD = uc.DefineFunction("FuncD() = 1+1") Console.WriteLine($"Elements in MyArrayA: {MyArrayA.Count}") Console.WriteLine($"Elements in MyArrayB: {MyArrayB.Count}") Console.WriteLine($"Params in FuncA(): {FunctionA.Count}") Console.WriteLine($"Params in FuncB(): {FunctionB.Count}") Console.WriteLine($"Params in FuncC(): {FunctionC.Count}") '// -1 or 2^n-1 (n=32 or 64) Console.WriteLine($"Params in FuncD(): {FunctionD.Count}") Console.WriteLine($"Operands in ! operator: {uc.ItemOf("!").Count}") Console.WriteLine($"Operands in > operator: {uc.ItemOf(">").Count}") End Sub End Module
Determining properties of an expression part
using uCalcSoftware;
var uc = new uCalc();
static void ItemCallback(uCalc.Callback cb) {
Console.WriteLine($"Name: {cb.Item.Name}");
Console.WriteLine($"Data type: {cb.Item.DataType.Name}");
Console.WriteLine($"Param count: {cb.Item.Count}");
Console.Write("Procedure type: ");
if (cb.Item.IsProperty(ItemIs.Operator)) {
Console.WriteLine("Operator");
} else if (cb.Item.IsProperty(ItemIs.Function)) {
Console.WriteLine("Function");
}
Console.WriteLine(cb.Item.Text);
Console.WriteLine(cb.Item.Description);
Console.WriteLine("---");
}
uc.DefineFunction("AAA() As Double", ItemCallback).Description = "Does this and that";
uc.DefineFunction("BBB(x, y, z) As String", ItemCallback).Description = "Does something else";
uc.DefineOperator("{x} CCC {y} As Int32", 0, Associativity.LeftToRight, ItemCallback);
uc.EvalStr("AAA()");
uc.EvalStr("BBB(9, 8, 7)");
uc.EvalStr("5 CCC 4");
Name: aaa
Data type: double
Param count: 0
Procedure type: Function
Function: AAA() As Double
Does this and that
---
Name: bbb
Data type: string
Param count: 3
Procedure type: Function
Function: BBB(x, y, z) As String
Does something else
---
Name: ccc
Data type: int
Param count: 2
Procedure type: Operator
Operator: {x} CCC {y} As Int32
--- using uCalcSoftware; var uc = new uCalc(); static void ItemCallback(uCalc.Callback cb) { Console.WriteLine($"Name: {cb.Item.Name}"); Console.WriteLine($"Data type: {cb.Item.DataType.Name}"); Console.WriteLine($"Param count: {cb.Item.Count}"); Console.Write("Procedure type: "); if (cb.Item.IsProperty(ItemIs.Operator)) { Console.WriteLine("Operator"); } else if (cb.Item.IsProperty(ItemIs.Function)) { Console.WriteLine("Function"); } Console.WriteLine(cb.Item.Text); Console.WriteLine(cb.Item.Description); Console.WriteLine("---"); } uc.DefineFunction("AAA() As Double", ItemCallback).Description = "Does this and that"; uc.DefineFunction("BBB(x, y, z) As String", ItemCallback).Description = "Does something else"; uc.DefineOperator("{x} CCC {y} As Int32", 0, Associativity.LeftToRight, ItemCallback); uc.EvalStr("AAA()"); uc.EvalStr("BBB(9, 8, 7)"); uc.EvalStr("5 CCC 4");
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
void ucalc_call ItemCallback(uCalcBase::Callback cb) {
cout << "Name: " << cb.Item().Name() << endl;
cout << "Data type: " << cb.Item().DataType().Name() << endl;
cout << "Param count: " << cb.Item().Count() << endl;
cout << "Procedure type: ";
if (cb.Item().IsProperty(ItemIs::Operator)) {
cout << "Operator" << endl;
} else if (cb.Item().IsProperty(ItemIs::Function)) {
cout << "Function" << endl;
}
cout << cb.Item().Text() << endl;
cout << cb.Item().Description() << endl;
cout << "---" << endl;
}
int main() {
uCalc uc;
uc.DefineFunction("AAA() As Double", ItemCallback).Description("Does this and that");
uc.DefineFunction("BBB(x, y, z) As String", ItemCallback).Description("Does something else");
uc.DefineOperator("{x} CCC {y} As Int32", 0, Associativity::LeftToRight, ItemCallback);
uc.EvalStr("AAA()");
uc.EvalStr("BBB(9, 8, 7)");
uc.EvalStr("5 CCC 4");
}
Name: aaa
Data type: double
Param count: 0
Procedure type: Function
Function: AAA() As Double
Does this and that
---
Name: bbb
Data type: string
Param count: 3
Procedure type: Function
Function: BBB(x, y, z) As String
Does something else
---
Name: ccc
Data type: int
Param count: 2
Procedure type: Operator
Operator: {x} CCC {y} As Int32
--- #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; void ucalc_call ItemCallback(uCalcBase::Callback cb) { cout << "Name: " << cb.Item().Name() << endl; cout << "Data type: " << cb.Item().DataType().Name() << endl; cout << "Param count: " << cb.Item().Count() << endl; cout << "Procedure type: "; if (cb.Item().IsProperty(ItemIs::Operator)) { cout << "Operator" << endl; } else if (cb.Item().IsProperty(ItemIs::Function)) { cout << "Function" << endl; } cout << cb.Item().Text() << endl; cout << cb.Item().Description() << endl; cout << "---" << endl; } int main() { uCalc uc; uc.DefineFunction("AAA() As Double", ItemCallback).Description("Does this and that"); uc.DefineFunction("BBB(x, y, z) As String", ItemCallback).Description("Does something else"); uc.DefineOperator("{x} CCC {y} As Int32", 0, Associativity::LeftToRight, ItemCallback); uc.EvalStr("AAA()"); uc.EvalStr("BBB(9, 8, 7)"); uc.EvalStr("5 CCC 4"); }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub ItemCallback(ByVal cb As uCalc.Callback)
Console.WriteLine($"Name: {cb.Item.Name}")
Console.WriteLine($"Data type: {cb.Item.DataType.Name}")
Console.WriteLine($"Param count: {cb.Item.Count}")
Console.Write("Procedure type: ")
If cb.Item.IsProperty(ItemIs.Operator) Then
Console.WriteLine("Operator")
ElseIf cb.Item.IsProperty(ItemIs.Function ) Then
Console.WriteLine("Function")
End If
Console.WriteLine(cb.Item.Text)
Console.WriteLine(cb.Item.Description)
Console.WriteLine("---")
End Sub
Public Sub Main()
Dim uc As New uCalc()
uc.DefineFunction("AAA() As Double", AddressOf ItemCallback).Description = "Does this and that"
uc.DefineFunction("BBB(x, y, z) As String", AddressOf ItemCallback).Description = "Does something else"
uc.DefineOperator("{x} CCC {y} As Int32", 0, Associativity.LeftToRight, AddressOf ItemCallback)
uc.EvalStr("AAA()")
uc.EvalStr("BBB(9, 8, 7)")
uc.EvalStr("5 CCC 4")
End Sub
End Module
Name: aaa
Data type: double
Param count: 0
Procedure type: Function
Function: AAA() As Double
Does this and that
---
Name: bbb
Data type: string
Param count: 3
Procedure type: Function
Function: BBB(x, y, z) As String
Does something else
---
Name: ccc
Data type: int
Param count: 2
Procedure type: Operator
Operator: {x} CCC {y} As Int32
--- Imports System Imports uCalcSoftware Public Module Program Public Sub ItemCallback(ByVal cb As uCalc.Callback) Console.WriteLine($"Name: {cb.Item.Name}") Console.WriteLine($"Data type: {cb.Item.DataType.Name}") Console.WriteLine($"Param count: {cb.Item.Count}") Console.Write("Procedure type: ") If cb.Item.IsProperty(ItemIs.Operator) Then Console.WriteLine("Operator") ElseIf cb.Item.IsProperty(ItemIs.Function ) Then Console.WriteLine("Function") End If Console.WriteLine(cb.Item.Text) Console.WriteLine(cb.Item.Description) Console.WriteLine("---") End Sub Public Sub Main() Dim uc As New uCalc() uc.DefineFunction("AAA() As Double", AddressOf ItemCallback).Description = "Does this and that" uc.DefineFunction("BBB(x, y, z) As String", AddressOf ItemCallback).Description = "Does something else" uc.DefineOperator("{x} CCC {y} As Int32", 0, Associativity.LeftToRight, AddressOf ItemCallback) uc.EvalStr("AAA()") uc.EvalStr("BBB(9, 8, 7)") uc.EvalStr("5 CCC 4") End Sub End Module