Takes a function and a name mapping, and returns a new function where
both the formals and all symbol references in the body have been
renamed according to the mapping. This is typically used after
from_example_to_function() to replace generated names like
param_1, param_2 with meaningful names.
Details
Validation
The function checks that:
All names in
mappingactually exist as formals offNew names are unique (no duplicates)
New names do not collide with parameters not being renamed
Limitation
If the body contains a nested function definition whose formals
shadow a parameter being renamed, the shadowed references in that
inner body will still be renamed. This is unlikely in practice
(parameters from from_example_to_function() are named param_N)
but is noted here for completeness.