1.24Variable parameters support

Functions giving informations on variable parameters.

Falcon supports variable parameter calling; a function or method may access the items that have been used in the parameter call by counting them and accessing them one by one.

Parameter passed by reference may be modified with the appropriate function.

This functions may be used whether the calling function provides a list of formal parameters or not. The first formal parameter will be treated as the variable parameter number zero, and the parameter count may be the same as, more than or less than the number of formal parameters. So, part of the parameters may be accessible via parameter names, and the others may be accessed with the functions in this group.

Functions

argd

Returns a dictionary containing all the parameters passed to the current function.

argd()

The dictionary contains the parameter names associated with the value passed by the caller. Parameters received beyond the officially declared ones aren't returned in this dictionary.

If the function doesn't declare any parameter, returns nil.

argv

Returns all the parameters of the current function as a vector.

argv()

If the current function doesn't receive any parameter, it returns nil.

paramCount

Returns number of parameter that have been passed to the current function or method.

paramCount()
ReturnThe parameter count.

The return value is the minimum value between the formal parameters declared for the current function and the number of actual parameters the caller passed. Formal parameters which are declared in the function header, but for which the caller didn't provide actual parameters, are filled with nil.

paramIsRef

Checks whether the nth parameter has been passed by reference or not.

paramIsRef( number )
number The paramter that must be checked (zero based)
Returntrue if the parameter has been passed by reference, false otherwise.
Raise
AccessError if number is out of range.

Both assigning a value to a certain parameter and using the paramSet() function will change locally the value of the parameter, but this value won't be reflected in the actual parameter that was used to call the function, unless the parameter was explicitly passed by reference. In some contexts, it may be useful to know if this is the case.

If the given parameter number cannot be accessed, a AccessError is raised.

paramSet

Changes the nth paramter if it has been passed by reference.

paramSet( number, value )
number the paramter to be changed (zero based)
value the new value for the parameter
Raise
AccessError if number is out of range.

The function is equivalent to assigning the value directly to the required parameter; of course, in this way also optional parameter may be accessed. If the required parameter was passed by reference, also the original value in the caller is changed.

If the given parameter number cannot be accessed, an AccessError is raised.

parameter

Gets the Nth parameter

parameter( pnum )
pnum The ordinal number of the paremeter, zero based
ReturnThe nth paramter (zero based) or NIL if the parameter is not given.
Raise
AccessError if pnum is out of range.

This function returns the required parameter, being the first one passed to the function indicated as 0, the second as 1 and so on. Both formally declared parameters and optional parameters can be accessed this way.

If the given parameter number cannot be accessed, a AccessError is raised.

Note: This function used to be called "paramNumber", and has been renamed in version 0.8.10. The function is still aliased throught the old function name for compatibility reason, but its usage is deprecated. Use parameter instead.

passvp

Returns all the undeclared parameters, or passes them to a callable item

passvp( [citem] )
citem Callable item on which to pass the parameters.
ReturnAn array containing unnamed parameters, or the return value b citem.

This function returns all the parameters passed to this function but not declared in its prototype (variable parameters) in an array.

If the host function doesn't receive any extra parameter, this function returns an empty array. This is useful in case the array is immediately added to a direct call. For example:


   function receiver( a, b )
      > "A: ", a
      > "B: ", b
      > "Others: ", passvp().describe()
   end

   receiver( "one", "two", "three", "four" )

If citem is specified, the function calls citem passing all the extra parameters to it. For example:


   function promptPrint( prompt )
      passvp( .[printl prompt] )
   end

   promptPrint( "The prompt: ", "arg1", " ", "arg2" )
Made with http://www.falconpl.org