Extract a nested let into a function.