Progress Programming Tips

By Rod Gaither (rdg@worldinfo.com)

PPT-34  Dynamic execution with RUN VALUE() and DYNAMIC-FUNCTION

Tip:

For a language with a fair number of static (early binding) constructs
one area has been dynamic (late binding) from the early days.  This is
the ability to do a RUN VALUE(expression).  With the addition of
Functions PSC has kept the flexibility associated with run by value
through the DYNAMIC-FUNCTION function.  A different wrapper but with a
similar purpose the DYNAMIC-FUNCTION allows you to use an expression
for both the function name and the in procedure handle.

Some examples where this flexibility can be used are -

1.  Dynamic menu systems

By storing program names in a database table and referencing the key
to that record in the menu item a single run value statement can be
used for the execution of any menu selection.

2.  SmartObject execution selection

When you issue a run dispatch("View") in your SmartObjects you are
calling a procedure (dispatch) that does an important translation. 
This is the selection of the appropriate "Event" style procedure. 
This dynamic selection is done by taking "VIEW" and prepending it with
the possible variations in the procedure handling chain - local,
custom, adm and then running by value the appropriate procedure.

The only problem with this dynamic approach is it is only partially
dynamic.  If the procedure or function take parameters then that part
of the call remains static.  For simple no parameter calls or some
standardized one parameter calls this can be dealt with.  For more
complex cases it gets difficult and even inappropriate as too much
context must be known to make the call.

3.  Passing in the comparison function

With the newness of 8.2 I don't have a handy, known example to
relate so I'll fall back on the example used in C when passing a
pointer to a function.

In a sort procedure the sort often consists of the algorithm, a
comparison operation, and an exchange operation.  The comparison
operation and exchange operations are independent of the particular
sort method being used and as such can be external functions passed
into the sort algorithm to be called.

This same technique can be applied with Progress functions
by passing in the name of the function and then using the
DYNAMIC-FUNCTION function to execute the function.  This kind of
technique allows for more flexibility in extending an existing
algorithm by letting some portions be determined by the caller via
passed in function references.


Wisdom:

Even in a modern 4GL the algorithms and techniques of older
languages can be used very effectively.


Rod Gaither                  | rdg@worldinfo.com
World Information Systems    | (910) 333-2580  Voice
Greensboro, NC               | (910) 333-2584  Fax