Definition: | object x = call_func(integer rid, sequence params) |
Description: |
Dynamically invoke the user-defined function with routine_id rid.
rid must be a valid routine id returned by routine_id(), and params must be a sequence of argument values of length n, where n is compatible with the number of arguments required by function rid. x will be the result returned by function rid. |
Comments: |
Calling a routine directly is known as a static call: it is determined at compile-time and cannot be
changed at run-time. Conversely, invoking a routine via a routine_id is known as a dynamic call: the
value of the routine_id can be altered at run-time and hence the routine being called can be altered
at run-time. While the trivial example below shows no benefits, the ability to store routine_ids in
tables (etc) is much more flexible, and often quite necessary for gui programming. Historically, a
routine_id was the only way to effect a forward call, but that is no longer the case.
If function rid does not take any arguments then s should be {}. |
Example: |
function sum2(integer a, inteber b) return a+b end function integer r_sum2 = routine_id("sum2") ?sum2(1,2) -- direct/static call ?call_func(r_sum2,{1,2}) -- indirect/dynamic call (equivalent) |
See Also: | call_proc, routine_id |