| 1 | = Rename variable = |
| 2 | |
| 3 | The "rename variable" transformation renames a variable and all of its occurrences. The only semantic information it requires is the scope and visibility of the variables. |
| 4 | |
| 5 | Rename X to Y: |
| 6 | |
| 7 | {{{ |
| 8 | max(X,Z) -> |
| 9 | if |
| 10 | X=<Z -> Z; |
| 11 | X>=Z -> X |
| 12 | end. |
| 13 | }}} |
| 14 | |
| 15 | Result: |
| 16 | |
| 17 | {{{ |
| 18 | max(Y,Z) -> |
| 19 | if |
| 20 | Y=<Z -> Z; |
| 21 | Y>=Z -> Y |
| 22 | end. |
| 23 | }}} |
| 24 | |
| 25 | == Side conditions == |
| 26 | |
| 27 | * The new variable name does not exist in the scope of the variable, either as a defined variable or as a visible variable. If it exists then the transformation starts an interaction to ask for a new variable name. |
| 28 | |
| 29 | * If the user does not specify a variable, the transformation starts an interaction to ask for a variable. It gives a list of variables which can be reached from the selected function clause. |
| 30 | |
| 31 | |
| 32 | == Transformation steps and compensations == |
| 33 | |
| 34 | 1. Replace every occurrence of the variable with the new name. In case of variable shadowing, other variables with the same name are not modified. |