4D Blog

Home Product A Fresh Approach to Writing Variadic Functions

A Fresh Approach to Writing Variadic Functions

October 23, 2023

Product

Many of you are familiar with using methods or functions that can accept an unspecified number of parameters, often referred to as variadic functions.

In our ongoing process to improve your development experience, 4D v20 R3 streamlined the declaration of these methods by introducing ellipsis, making your code more straightforward and easier to work with.

In your function or method declaration, you can now employ “…” in your last parameter to specify that the number of parameters is variable. These suspension points can be supplemented by a type. This type is then used by 4D to check the type of parameters received by the function or method.

For example, if you want to create a SumNumbers method that sums all the numbers passed as parameters:

#DECLARE( ...  : Real) : Real
var $number; $total : Real
var $i : Integer

For ($i; 1; Count parameters)
	$total+= ${$i}
End for 

return $total

This method can be called with a variable number of parameters:

$total1:=SumNumbers // returns 0

$total2:=SumNumbers(1; 2; 3; 4; 5) // returns 15

With this syntax, 4D now checks the parameter types for you:

$total3:=SumNumbers(1; 2; "test"; 4; 5) // returns an error

But if you want to accept any type, use “…” without type:

function AcceptAllType(...)
var $value : variant

For each ($value; Copy parameters())
   // your code here
End for each 

Take advantage of this new syntax to create flexible functions or methods, and feel free to explore these features in greater detail by referring to the documentation!

Discuss

Tags 21, Function, Language, Programming, v20 R3

Latest related posts

  • December 3, 2025

    Give AI to a 30 years old 4D application

  • November 28, 2025

    ORDA – Handle an event-driven logic during database operations

  • November 27, 2025

    ORDA – Permissions – Restrict / allow web access to the resources in one click

Fabrice Mainguené
Fabrice Mainguené
• Product Owner •Fabrice Mainguené joined 4D Program team in November, 2016. As a Product Owner, he is in charge of writing the user stories then translating it to functional specifications. His role is also to make sure that the feature implementation delivered is meeting the customer need.After obtaining a Bachelor degree in Computer Science at CNAM, Fabrice joined a small software publishing company as a Windev developer. Then he worked for different companies in industry and trade areas as a Windev and web developer as well as technical advisor on new features.
  • Deutsch
  • Français
  • English
  • Português
  • Čeština
  • Español
  • Italiano
  • 日本語

Categories

Browse categories

  • 4D View Pro
  • AI
  • 4D Write Pro
  • 4D for Mobile
  • Email
  • Development Mode
  • 4D Language
  • ORDA
  • User Interface / GUI
  • Qodly Studio
  • Server
  • Maintenance
  • Deployment
  • 4D Tutorials
  • Generic
  • 4D Summit sessions and other online videos

Tags

4D-Analyzer 4D AIKit 4D for Android 4D for iOS 4D NetKit 4D Qodly Pro 4D View Pro 4D Write Pro 20 R10 21 Administration AI Artificial Intelligence Build application Class Client/Server Code editor Collections Formula Listbox Logs Mail Microsoft 365 Network Objects OpenAI ORDA PDF Pictures Preemptive Programming REST Scalability Security Session Source control Speed Spreadsheet Tutorial UI User Experience v20 vscode Web Word processor

Tags

4D-Analyzer 4D AIKit 4D for Android 4D for iOS 4D NetKit 4D Qodly Pro 4D View Pro 4D Write Pro 20 R10 21 Administration AI Artificial Intelligence Build application Class Client/Server Code editor Collections Formula Listbox Logs Mail Microsoft 365 Network Objects OpenAI ORDA PDF Pictures Preemptive Programming REST Scalability Security Session Source control Speed Spreadsheet Tutorial UI User Experience v20 vscode Web Word processor
Subscribe to 4D Newsletter

© 2025 4D SAS - All rights reserved
Terms & Conditions | Legal Notices | Data Policy | Cookie Policy | Contact us | Write for us


Subscribe to 4D Newsletter

* Your privacy is very important to us. Please click here to view our Policy

Contact us

Got a question, suggestion or just want to get in touch with the 4D bloggers? Drop us a line!

* Your privacy is very important to us. Please click here to view our Policy