CS 61A: Structure and Interpretation of Computer Programs - week1 - 2

·  阅读 42

Looking Up Names In Environments

Every expression is evaluated in the context of an environment. So far, the current environment is either:

• The global frame alone, or
• A local frame, followed by the global frame.

Most important two things I’ll say all day:

An environment is a sequence of frames.
A name evaluates to the value bound to that name in the earliest frame of the current environment in which that name is found.

E.g., to look up some name in the body of the square function: • Look for that name in the local frame. • If not found, look for it in the global frame.

这个,你答对了吗

def square(x):
    return mul(x, x)
    
# Name conflicts
def square(square):
    return mul(square, square)
分类:
后端
标签:
分类:
后端
标签:
收藏成功!
已添加到「」, 点击更改