## Chapter 4. Bound Variable Renaming (*)

4.1. Renaming Bound Variables
4.2. Example

### Work in Progress

This chapter is work in progress. Not all parts have been finished yet. The latest revision of this manual may contain more material. Refer to the online version.

renaming of bound variables

## 4.1. Renaming Bound Variables

Figure 4.1. file: til/renaming/til-rename-vars.str

```module til-rename-vars
imports TIL liblib
strategies

io-til-rename-vars =
io-wrap(til-rename-vars)

til-rename-vars =
Var(RenameVar)
<+ Assign(RenameVar, til-rename-vars)
<+ For(RenameVar, til-rename-vars, til-rename-vars, til-rename-vars)
<+ RenameDeclaration
<+ Block({| RenameVar : map(til-rename-vars) |})
<+ all(til-rename-vars)

RenameDeclaration :
Declaration(x) -> Declaration(y)
where <newname> x => y
; rules( RenameVar : x -> y )

RenameDeclaration :
DeclarationTyped(x, t) -> DeclarationTyped(y, t)
where <newname> x => y
; rules( RenameVar : x -> y )
```

## 4.2. Example

Figure 4.2. file: til/xmpl/rename-test

```sglri -p ../syn/TIL.tbl -i test1.til |\
../renaming/til-rename-vars |\
ast2text -p ../pp/TIL-pretty.pp -o test1.rn.txt
```

Table 4.1. files: til/xmpl/test1.til, til/xmpl/test1.rn.txt

beforeafter
```// TIL program computing the factorial

var n;
var x;
var fact;
fact := 1;
for x := 1 to n do
fact := x * fact;
end
write("factorial of ");
writeint(n);
write(" is ");
writeint(fact);
write("\n");
```
```var n0;