This seems similar to the question that came up in this thread: Can a function return another function?
Apparently, it’s considered a bug or unwanted limitation. But I don’t really see why this should work. Dynamically creating named functions at runtime seems unnatural to me.
Isn’t this metaprogramming, that should require a macro? Or, if you don’t really need a globally defined name, make an anonymous function.