How does one write a Variadic Function in Microsoft Visual Foxpro?
A variadic function is one that accepts a variable number of arguments - see http://en.m.wikipedia.org/wiki/Variadic_function. Examples are given for just about every other programming language in the world at http://rosettacode.org/wiki/Variadic_function but not the good ol' fox.
So given the following function:
Function PrintVars(var1,var2,var3)
? var1
? var2
? var3
End Func
How do we allow any number of arguments?
You have a limited ability to do this in VFP.
Call this like this: printvars(1, 2)
and your results will be:
VFP will initialize any parameter you don't explicitly pass with a logical .F. value. The PARAMETERS() function obviously tells you how many were actually passed.
Passing too many parameters will give you an error that your PARAMETER statement needs to specify more parameters.