From Programming Language Pragmatics by Scott, Figure 3.14 Deep binding in Python. At right is a conceptual view of the run-time stack.  Referencing environments captured in closures are shown as dashed boxes and arrows. When  B is called via formal parameter P, two instances of I exist. Because the closure for P was  created in the initial invocation of A, Bs static link (solid arrow) points to the frame of that earlier  invocation. B uses that invocations instance of I in its print statement, and the output is a 1.The catch is that a running program may have more than one instance of an object that is declared within a recursive subroutine. A closure in a language with  static scoping captures the current instance of every object, at the time the closure  is created. When the closures subroutine is called, it will nd these captured instances, even if newer instances have subsequently been created by recursive calls.So basically, the quote tries to explain that the following program (which is the same as the one in the screenshot) prints out 1:def A(I, P):    def B():        print(I)    # body of A:    if I > 1:        P()    else:        A(2, B)def C():    pass # do nothingA(1, C) # main programI don't quite understand the reason being because the closure for P wascreated in the initial invocation of A, Bs static link (solid arrow) points to the frame of that earlier invocation, and When the closures subroutine is called,  it will nd these captured instances. So I modify the example, and then the new example prints out 2 instead of 1:def A(I, P):    def B():        print(I)    if I > 2:        P()    elif I > 1:        A(3, B)    else:        A(2, B)def C():    passA(1, C)Another modified example prints 1:def A(I, P):    def B():        print(I)    if I > 2:        P()    elif I > 1:        A(3, P)    else:        A(2, B)def C():    passA(1, C)So how can I know which closure matters when resolving a nonlocal name in a language with deep binding? Generally, is a closure created whenever a function is passed as an argument to another function?Thanks.
How shall I resolve a nonlocal name in a language with deep binding?
programming languages;variable binding