Closures in JS, Python
Posted on October 2, 2021
Tags: javascript
1 Lambda
\[\lambda x. funcbody\]
“lambda x” is a binder whose scope is “funcbody”. An occurance of variable x is bound when it occus in “funcbody” of a “lambda x. funcbody”
b
is shown in the function argument and the global scope but they will NEVER refer to the sameb
. We can pretend that the function always renames conflicting names fromb
tob_frame
.- Technically the reason they never refer to the same object, is because the global b lives in the global frame and when f is called another stackframe is placed so that the argument b lives in the function stack frame.
def f(b): #stackframe
= 4
b return ..
= 6 #globalscope b
def f(b_frame1):
= 4
b_frame1 return ..
= 6 #globalscope b
frames objects
---
globalframe
b ------------> 6
---
f frame
b ------------> 4
---