| 1 | = Rename record field = |
| 2 | |
| 3 | The rename record field transformation supports renaming the specified field of a record. The name of the field is replaced in the definition form and in every referrer expression and token to the given new name. To the field belongs a semantic field object linked to the record, it stores the field name. The data of this object is updated too. |
| 4 | |
| 5 | Renaming field {{{name}}} to {{{id}}}: |
| 6 | |
| 7 | {{{ |
| 8 | -record(member, {name, age}). |
| 9 | |
| 10 | rename(Arg, New) -> |
| 11 | #member{name=Name} = Arg, |
| 12 | io:format("%s == %s", |
| 13 | [Name, Arg#member.name]), |
| 14 | Arg#member{name=New}. |
| 15 | }}} |
| 16 | |
| 17 | Result: |
| 18 | |
| 19 | {{{ |
| 20 | -record(member, {id, age}). |
| 21 | |
| 22 | rename(Arg, New) -> |
| 23 | #member{id=Name} = Arg, |
| 24 | io:format("%s == %s", |
| 25 | [Name, Arg#member.id]), |
| 26 | Arg#member{id=New}. |
| 27 | }}} |
| 28 | |
| 29 | == Side conditions == |
| 30 | |
| 31 | * The record must have no field with the same name as the given new field name. If it has, the transformation starts an interaction to ask for a new record field name. |
| 32 | |
| 33 | * If the user does not specify a record field, then the transformation starts an interaction to ask the user to specify one. |
| 34 | |
| 35 | == Transformation steps and compensations == |
| 36 | |
| 37 | 1. The field name is changed to the new name in the definition of the record and in every record expression that refers the field. |