wiki:RefactoringSteps/RenameVariable

Rename variable

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.

Rename X to Y:

max(X,Z) ->
   if
      X=<Z -> Z;
      X>=Z -> X
   end.

Result:

max(Y,Z) ->
   if
      Y=<Z -> Z;
      Y>=Z -> Y
   end.

Side conditions

  • 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.
  • 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.

Transformation steps and compensations

  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.
Last modified 12 years ago Last modified on Feb 15, 2012, 1:48:37 PM