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.

ArgCount

Method

Product: 

Fast Math Parser

Class: 

Callback

Gets the number of arguments passed to the current callback function, essential for creating variadic functions.

Syntax

ArgCount()

Parameters

[None]

Return

int

The total number of arguments passed to the callback. Returns 0 if the function was called with no arguments.

Remarks

The ArgCount method returns the total number of arguments passed to a callback function. It is the primary tool for creating variadic functions—functions that can accept a variable number of arguments.

This method can only be called from within a callback context, typically one registered via DefineFunction or DefineOperator. It is commonly used as the upper bound for a loop that iterates through the provided arguments.

static void MySum(uCalc.Callback cb) {double total = 0;// Use ArgCount() to determine how many times to loop.for (int i = 1; i <= cb.ArgCount(); i++) {   total = total + cb.Arg(i);}cb.Return(total);}// The '...' syntax marks this as a variadic function.uc.DefineFunction("Sum(...)", MySum);Console.WriteLine(uc.Eval("Sum(10, 20, 30)")); // Outputs 60

💡 Comparative Analysis

Most modern languages have a mechanism for variadic functions, but uCalc's integration with its dynamic expression engine is unique.

  • vs. C# params / C++ ...: In compiled languages, variadic functions are a compile-time feature. The function signature is fixed in code.

    // C# Examplepublic double Sum(params double[] numbers) { ... }

    uCalc's advantage is its runtime dynamism. A user can define a variadic function within a string expression that is evaluated at runtime, providing a level of flexibility impossible in pre-compiled code. The ArgCount method is the key that unlocks this capability within the callback's logic.

  • vs. JavaScript ...args: While JavaScript's rest parameters (...args) are also dynamic, uCalc's ArgCount and its companion methods (Arg, ArgItem, etc.) provide a more structured and type-aware API for inspecting arguments from within a strongly-typed host environment (like C# or C++), which is a distinct advantage over loosely-typed scripting.

Examples

Defining a callback function with a variable number of arguments
				
					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());
}

uc.DefineFunction("Average(x ...)", MyAverage);
Console.WriteLine(uc.Eval("Average(10, 3, 7, 4)"));
				
			
6
				
					#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;
   uc.DefineFunction("Average(x ...)", MyAverage);
   cout << uc.Eval("Average(10, 3, 7, 4)") << endl;
}
				
			
6
				
					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()
      uc.DefineFunction("Average(x ...)", AddressOf MyAverage)
      Console.WriteLine(uc.Eval("Average(10, 3, 7, 4)"))
   End Sub
End Module
				
			
6
Passing arg ByHandle to retrieve meta data such as arg data type; and AnyType
				
					using uCalcSoftware;

var uc = new uCalc();

static void DisplayArgs(uCalc.Callback cb) {
   for (int x = 1; x <= cb.ArgCount(); x++) {
      Console.WriteLine(cb.ArgItem(x).ValueStr() + "  Type: " + cb.ArgItem(x).DataType.Name);
   }
}

uc.DefineFunction("DisplayArgs(ByHandle Arg As AnyType ...)", DisplayArgs);
uc.Eval("DisplayArgs(5, 3+2*#i, 'Hello', True, False, Int16(5+4.1))");
				
			
5  Type: double
3+2i  Type: complex
Hello  Type: string
true  Type: bool
false  Type: bool
9  Type: int16
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

void ucalc_call DisplayArgs(uCalcBase::Callback cb) {
   for (int x = 1; x <= cb.ArgCount(); x++) {
      cout << cb.ArgItem(x).ValueStr() + "  Type: " + cb.ArgItem(x).DataType().Name() << endl;
   }
}
int main() {
   uCalc uc;
   uc.DefineFunction("DisplayArgs(ByHandle Arg As AnyType ...)", DisplayArgs);
   uc.Eval("DisplayArgs(5, 3+2*#i, 'Hello', True, False, Int16(5+4.1))");
}
				
			
5  Type: double
3+2i  Type: complex
Hello  Type: string
true  Type: bool
false  Type: bool
9  Type: int16
				
					Imports System
Imports uCalcSoftware
Public Module Program
   
   Public Sub DisplayArgs(ByVal cb As uCalc.Callback)
      For x  As Integer = 1 To cb.ArgCount()
         Console.WriteLine(cb.ArgItem(x).ValueStr() + "  Type: " + cb.ArgItem(x).DataType.Name)
      Next
   End Sub
   Public Sub Main()
      Dim uc As New uCalc()
      uc.DefineFunction("DisplayArgs(ByHandle Arg As AnyType ...)", AddressOf DisplayArgs)
      uc.Eval("DisplayArgs(5, 3+2*#i, 'Hello', True, False, Int16(5+4.1))")
   End Sub
End Module
				
			
5  Type: double
3+2i  Type: complex
Hello  Type: string
true  Type: bool
false  Type: bool
9  Type: int16