I have a nested function as follow:

def make_adder(n):
    def add(x):
        return x + n
    return add
>>> plus_3 = make_adder(3)
>>> plus_5 = make_adder(5)
>>> plus_3(4) 7
>>> plus_5(4) 9

What's the formal names of make_adder and add?
Can I call them 'outer function' and 'inner function'?

  • $\begingroup$ I can't think of a completely standard term, but I believe your terms (outer/inner) are sometimes used. I think I also heard top-level/nested function, and global/local function. None of these term properly "scale" to multiple nestings, though. $\endgroup$ – chi Nov 29 '17 at 17:39

A function that either takes a function as argument or returns a function as result is called a High Order Function in functional programming. Your function make_adder is doing the latter.


One specific name for that kind of construct is "closure". That term specifically refers to a situation where the inner function uses variables from the outer function's "enclosing" namespace.

  • $\begingroup$ That term is uses for so many different things, it hardly qualifies as "formal". $\endgroup$ – Raphael Nov 30 '17 at 7:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.