Definition: | call_proc(integer rid, sequence params) |
Description: |
Dynamically invoke the user-defined procedure with routine_id rid.
rid: a valid routine id as returned by routine_id(). params: a sequence of argument values of length n, where n is compatible with the number of arguments required by the procedure identified by 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. If you need a
routine to be invoked whenever a particular event occurs, the easiest way is to use a routine_id.
Historically, a routine_id was the only way to effect a forward call, but that is no longer the case.
If the procedure identified by rid does not take any arguments then s should be {}. |
Example: |
procedure foo(integer fn, string s) puts(fn, s) end procedure integer r_foo = routine_id("foo") foo(1,"Hello World\n") -- direct/static call call_proc(r_foo,{1,"Hello World\n"}) -- indirect/dynamic call (equivalent) |
See Also: | call_func, routine_id |