terminology: does "closure" refer more to definition or to instance?

11 Views Asked by At

motivating example in python, though this is not python-specific.

def make_foo(x):
  def foo(y):
    return x + y

def make_bar(x):
  def bar(y):
    return x - y

f = make_foo(1)
b1 = make_bar(1)
b2 = make_bar(2)

how many closures are there in this code snippet? Is it two (foo and bar), or three (f, b1, b2). If I'm not being precise, I would be comfortable referring to any of those as a closure.

What are the most appropriate terms when I want to be precise? Here are a few options I can think of.

  • closure definition vs closure object
  • closure type vs closure instance

If I use one precise term, which should get the more generic "closure" title?

  • closure vs closure instance
  • closure definition vs closure

I'm also interested in the analogous question for coroutines (and maybe functions, though it comes up less often, since it's less common to have multiple "instances" of a function with distinct state - maybe e.g. if they're executing concurrently on multiple threads).

0

There are 0 best solutions below