Re: call_func()
- Posted by petelomax Jan 25, 2016
- 1492 views
Suggestion:
call_proc(integer rid, sequence params)
Description:
Dynamically invoke the user-defined procedure 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 procedure 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 procedure rid does not take any arguments then params should be {}.
Example:
procedure foo(integer a, sequence s) puts(a, 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)
Improvements welcome