Search code examples
functionabstraction

Are Nested functions considered Higher order functions?


I know by definition higher order functions are functions that receive a function as a parameter or return a function.

I want to know if a nested function is considered a higher order function since there are functions defined inside of it, and if it is the case are nested functions that return a dispatch dictionary considered higher order as well?(they may not receive a function but they do return a dictionary which can activate a function but its not a function up until activation with a correct key).


Solution

  • No, a nested function is not higher-order. As you noted, "higher order functions are functions that receive a function as a parameter or return a function." It is "higher-order" because it is a function that operates on functions. Nesting a function does not do that. It simply modifies its scope. Similarly, a closure (which in most languages has many similarities to a nested function), is not itself a higher-order function.