Next: Multiple Subscripts, Previous: Range Subscripts, Up: Subscripts [Contents][Index]
The elements of lists (Lists) and structures (Structures) in argument lists can be interpreted by LUX as individual arguments rather than as members of a single argument. This is a mechanism for specifying arbitrary numbers of arguments, and for assembling argument lists on the fly. For LUX to interpret lists and structures as such, they must themselves contain a single list or structure. This way we can distinguish between the case where the user wants to specify a list or structure as a single argument, and the case where the user wants to specify a list or structure as a set of arguments, without causing too much trouble.
For example, FOO( x, y, { { a, b } }, z)
is interpreted as
FOO( x, y, a, b, z)
, but in FOO( x, y, { a, b }, z)
, the
list is a single argument. If q
is equal to { a, b }
,
then FOO( x, y, { q }, z)
is interpreted as the first example
above, and FOO( x, y, q, z)
like the second one.
Lists and structures contained within a list or structure that is interpreted as a set of arguments are also expanded into arguments: the expansion is performed one level at a time.
This method can be used to support functions with variable number of arguments. For example, suppose you want to write a function that constructs a file name by combining an arbitrary file name format with the corresponding number of arguments. You want your function to be able to deal with any file name format and any corresponding number of arguments. Using lists of arguments, this can be done as follows:
FUNC FILENAME(format,args) RETURN,FSTRING(format, { {args} }) ENDFUNC
The enclosure of args
in double curly braces in the function
definition ensures that this argument is expanded into a list of
arguments. The call filename('file%03d',7)
now returns
'file007'
, and filename('file-%s-%03d',{'second',7})
yields 'file-second-007'
. The two arguments 'second'
and
7
must be enclosed in curly braces.
Next: Multiple Subscripts, Previous: Range Subscripts, Up: Subscripts [Contents][Index]