PYTHON Call expressions, such as square(2), apply functions to arguments. When executing call expressions, we create a new frame in our diagram to keep track of local variables: Evaluate the operator, which should evaluate to a function. Evaluate the operands from left to right. Draw a new frame, labeling it with the following: A unique index (f1, f2, f3, ...) The intrinsic name of the function, which is the name of the function object itself. For example, if the function object is func square(x) [parent=Global], the intrinsic name is square. The parent frame ([parent=Global]) Bind the formal parameters to the argument values obtained in step 2 (e.g. bind x to 3). Evaluate the body of the function in this new frame until a return value is obtained. Write down the return value in the frame.   If a function does not have a return value, it implicitly returns None. In that case, the “Return value" box should contain None.   Let's put it all together! Draw an environment diagram for the following code. def double(x):     return x * 2 hmmm = double wow = double(3) hmmm(wow)

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

PYTHON

Call expressions, such as square(2), apply functions to arguments. When executing call expressions, we create a new frame in our diagram to keep track of local variables:

  1. Evaluate the operator, which should evaluate to a function.
  2. Evaluate the operands from left to right.
  3. Draw a new frame, labeling it with the following:
    • A unique index (f1, f2, f3, ...)
    • The intrinsic name of the function, which is the name of the function object itself.
      For example, if the function object is func square(x)
      [parent=Global], the intrinsic name is square.
    • The parent frame ([parent=Global])
  4. Bind the formal parameters to the argument values obtained in step 2 (e.g. bind x to 3).
  5. Evaluate the body of the function in this new frame until a return value is obtained. Write down the return value in the frame.

 

If a function does not have a return value, it implicitly returns None. In that case, the “Return value" box should contain None.

 

Let's put it all together! Draw an environment diagram for the following code.

def double(x):

    return x * 2


hmmm = double

wow = double(3)

hmmm(wow)

 
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Functions
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education