Variadic Functions in OpenSCAD
Our next program demonstrates variadic functions, which allow a function to accept an arbitrary number of arguments. For instance, fmt.Println
is a common example of such a function.
Here’s a function that will take an arbitrary number of int
values as arguments.
In this code, the sum
function takes an array of integers as an argument. Within the function, the array is iterated to calculate the total sum.
Variadic functions in OpenSCAD are handled by passing a list or array of arguments, as shown. The function sum_nums
is used recursively to compute the total sum of the numbers in the array.
To see the output, you can run the code in OpenSCAD and watch the echoed values:
Let’s explore more functionalities of OpenSCAD in the next examples.