skip to main content
RPL: A Hybrid Approach
The requirements of RPL point to an ideal language that has some elements of both imperative and functional programming languages. For example, the ultimate purpose of RPL as the rule language is to set slots in the model in order to drive the simulation. Therefore, it is necessary to have assignment statements, particularly to slots. The slots in the model maintain the state of the system for the rules, thus are analogous to values in memory. To maintain clarity of meaning for rule assignments, all assignments are done at the very top level of the rules. In fact, rules contain only slot assignment statements and print statements. Each slot is assigned the result of an expression or function evaluation, No slot assignments are “hidden” in lower level functions.
RiverWare rules have the following form:
Object.slot[timestep] = <expression>
where the expression could contain complex logic or be as simple as a single function call.
The rules need to look at the current state of the model, so the language must have the ability to read slot values from memory. This does not diminish the referential transparency of the rules because slot values in the model can never change while a rule is executing. Data that is associated with policy, for example reservoir guide curves and minimum flow values, are kept in custom slots in the model.
Beyond the assignments to slots, policy computation is performed exclusively by evaluating functions and expressions, providing the benefits of being able to follow the meaning of the rule and not having hidden side effects. To assist in policy that frequently references the same variable, the WITH expression allows the use of a local variable within an expression. This feature helps the user to write policies which are more efficient and simpler than they might otherwise be.
 
Revised: 08/02/2021