20 lines
401 B
Go
20 lines
401 B
Go
package lambda
|
|
|
|
func Rename(e Expression, target string, substitute string) {
|
|
switch e := e.(type) {
|
|
case *Variable:
|
|
if e.Value == target {
|
|
e.Value = substitute
|
|
}
|
|
case *Abstraction:
|
|
if e.Parameter == target {
|
|
e.Parameter = substitute
|
|
}
|
|
|
|
Rename(e.Body, target, substitute)
|
|
case *Application:
|
|
Rename(e.Abstraction, target, substitute)
|
|
Rename(e.Argument, target, substitute)
|
|
}
|
|
}
|