In python there is the *args convention I am wondering if CF9 supports something similar.
Here is the python example
>>> def func(*args):
for a in args:
print a, "is a quality argument"
>>> func(1, 2, 3)
1 is a quality argument
2 is a quality argument
3 is a quality argument
>>>
Yes, CFML has supported dynamic arguments for as long as it has supported user-defined functions.
All arguments, whether explicitly defined, or whether passed in without being defined, exist in the Arguments scope.
The Arguments scope can be treated as both an array and a structure (key/value).
Here is the closest equivalent to your example, using script syntax:
Note that
ain this example is the key name, not the value, hence whyarguments[a]is used.To be treated as code, the above script must either be within
<cfscript>..</cfscript>tags, or alternatively inside acomponent {..}block inside a.cfcfile.Here’s a couple of tag versions, the first equivalent to the for/in loop:
And this one allows you to access the value directly (i.e.
ais the value here):In Railo* CFML, this last example can be expressed in script as:
*Railo is one of two Open Source alternatives to Adobe ColdFusion, the other being Open BlueDragon.