61a lecture 2 · discussion question 1 what is the value of the final expression in this sequence?...
TRANSCRIPT
![Page 1: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/1.jpg)
61A Lecture 2
![Page 2: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/2.jpg)
Announcements
![Page 3: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/3.jpg)
Names, Assignment, and User-Defined Functions
(Demo)
![Page 4: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/4.jpg)
Types of Expressions
4
![Page 5: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/5.jpg)
Types of Expressions
Primitive expressions:
4
![Page 6: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/6.jpg)
Types of Expressions
Primitive expressions: 2
Number or Numeral
4
![Page 7: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/7.jpg)
Types of Expressions
Primitive expressions: 2 add
Number or Numeral Name
4
![Page 8: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/8.jpg)
Types of Expressions
Primitive expressions: 2 add 'hello'
Number or Numeral Name String
4
![Page 9: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/9.jpg)
Types of Expressions
Primitive expressions:
Call expressions:
2 add 'hello'
Number or Numeral Name String
4
![Page 10: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/10.jpg)
Types of Expressions
Primitive expressions:
Call expressions:
2 add 'hello'
max ( 2 , 3 )
Number or Numeral Name String
4
![Page 11: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/11.jpg)
Types of Expressions
Primitive expressions:
Call expressions:
2 add 'hello'
max ( 2 , 3 )
Operator
Number or Numeral Name String
4
![Page 12: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/12.jpg)
Types of Expressions
Primitive expressions:
Call expressions:
2 add 'hello'
max ( 2 , 3 )
Operator Operand Operand
Number or Numeral Name String
4
![Page 13: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/13.jpg)
Types of Expressions
Primitive expressions:
Call expressions:
2 add 'hello'
max ( 2 , 3 )
Operator Operand Operand
max(min(pow(3, 5), -4), min(1, -2))
Number or Numeral Name String
4
![Page 14: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/14.jpg)
Types of Expressions
Primitive expressions:
Call expressions:
2 add 'hello'
max ( 2 , 3 )
Operator Operand Operand
max(min(pow(3, 5), -4), min(1, -2))
Number or Numeral Name String
4
An operand can also be a call expression
![Page 15: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/15.jpg)
Types of Expressions
Primitive expressions:
Call expressions:
2 add 'hello'
max ( 2 , 3 )
Operator Operand Operand
max(min(pow(3, 5), -4), min(1, -2))
Number or Numeral Name String
4
An operand can also be a call expression
![Page 16: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/16.jpg)
Discussion Question 1
5
![Page 17: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/17.jpg)
Discussion Question 1
What is the value of the final expression in this sequence?
5
![Page 18: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/18.jpg)
Discussion Question 1
What is the value of the final expression in this sequence?
>>> f = min
5
![Page 19: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/19.jpg)
Discussion Question 1
What is the value of the final expression in this sequence?
>>> f = min
>>> f = max
5
![Page 20: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/20.jpg)
Discussion Question 1
What is the value of the final expression in this sequence?
>>> f = min
>>> f = max
>>> g, h = min, max
5
![Page 21: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/21.jpg)
Discussion Question 1
What is the value of the final expression in this sequence?
>>> f = min
>>> f = max
>>> g, h = min, max
>>> max = g
5
![Page 22: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/22.jpg)
Discussion Question 1
What is the value of the final expression in this sequence?
>>> f = min
>>> f = max
>>> g, h = min, max
>>> max = g
>>> max(f(2, g(h(1, 5), 3)), 4)
5
![Page 23: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/23.jpg)
Discussion Question 1
What is the value of the final expression in this sequence?
>>> f = min
>>> f = max
>>> g, h = min, max
>>> max = g
>>> max(f(2, g(h(1, 5), 3)), 4)
???
5
![Page 24: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/24.jpg)
Discussion Question 1
What is the value of the final expression in this sequence?
>>> f = min
>>> f = max
>>> g, h = min, max
>>> max = g
>>> max(f(2, g(h(1, 5), 3)), 4)
???
5
![Page 25: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/25.jpg)
Environment Diagrams
![Page 26: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/26.jpg)
Environment Diagrams
Environment diagrams visualize the interpreter’s process.
7Interactive Diagram
![Page 27: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/27.jpg)
Environment Diagrams
Environment diagrams visualize the interpreter’s process.
7Interactive Diagram
![Page 28: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/28.jpg)
Environment Diagrams
Environment diagrams visualize the interpreter’s process.
7Interactive Diagram
![Page 29: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/29.jpg)
Environment Diagrams
Frames (right):Code (left):
Environment diagrams visualize the interpreter’s process.
7Interactive Diagram
![Page 30: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/30.jpg)
Environment Diagrams
Statements and expressions
Frames (right):Code (left):
Environment diagrams visualize the interpreter’s process.
7Interactive Diagram
![Page 31: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/31.jpg)
Environment Diagrams
Import statement
Statements and expressions
Frames (right):Code (left):
Environment diagrams visualize the interpreter’s process.
7Interactive Diagram
![Page 32: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/32.jpg)
Environment Diagrams
Import statement
Statements and expressions
Frames (right):Code (left):
Environment diagrams visualize the interpreter’s process.
7
Assignment statement
Interactive Diagram
![Page 33: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/33.jpg)
Environment Diagrams
Import statement
Statements and expressions
Arrows indicate evaluation order
Frames (right):Code (left):
Environment diagrams visualize the interpreter’s process.
7
Assignment statement
Interactive Diagram
![Page 34: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/34.jpg)
Environment Diagrams
Import statement
Statements and expressions
Arrows indicate evaluation order
Frames (right):Code (left):
Environment diagrams visualize the interpreter’s process.
7
Just executed
Assignment statement
Interactive Diagram
![Page 35: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/35.jpg)
Environment Diagrams
Import statement
Statements and expressions
Arrows indicate evaluation order
Frames (right):Code (left):
Environment diagrams visualize the interpreter’s process.
7
Just executed
Next to execute Assignment statement
Interactive Diagram
![Page 36: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/36.jpg)
Environment Diagrams
Import statement
Each name is bound to a valueStatements and expressions
Arrows indicate evaluation order
Frames (right):Code (left):
Environment diagrams visualize the interpreter’s process.
7
Just executed
Next to execute Assignment statement
Interactive Diagram
![Page 37: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/37.jpg)
Environment Diagrams
Name
Import statement
Each name is bound to a valueStatements and expressions
Arrows indicate evaluation order
Frames (right):Code (left):
Environment diagrams visualize the interpreter’s process.
7
Just executed
Next to execute Assignment statement
Interactive Diagram
![Page 38: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/38.jpg)
Environment Diagrams
Name Value
Import statement
Each name is bound to a valueStatements and expressions
Arrows indicate evaluation order
Frames (right):Code (left):
Environment diagrams visualize the interpreter’s process.
7
Just executed
Next to execute Assignment statement
Interactive Diagram
![Page 39: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/39.jpg)
Environment Diagrams
Name Value
Import statement
Each name is bound to a value
Within a frame, a name cannot be repeated
Statements and expressions
Arrows indicate evaluation order
Frames (right):Code (left):
Environment diagrams visualize the interpreter’s process.
7
Just executed
Next to execute Assignment statement
Interactive Diagram
![Page 40: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/40.jpg)
Environment Diagrams
(Demo)
Name Value
Import statement
Each name is bound to a value
Within a frame, a name cannot be repeated
Statements and expressions
Arrows indicate evaluation order
Frames (right):Code (left):
Environment diagrams visualize the interpreter’s process.
7
Just executed
Next to execute Assignment statement
Interactive Diagram
![Page 41: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/41.jpg)
Assignment Statements
8Interactive Diagram
![Page 42: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/42.jpg)
Assignment Statements
8Interactive Diagram
![Page 43: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/43.jpg)
Assignment Statements
8Interactive Diagram
![Page 44: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/44.jpg)
Assignment Statements
8
Just executed
Interactive Diagram
![Page 45: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/45.jpg)
Assignment Statements
8
Just executed
Next to execute
Interactive Diagram
![Page 46: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/46.jpg)
Assignment Statements
Execution rule for assignment statements:
8
Just executed
Next to execute
Interactive Diagram
![Page 47: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/47.jpg)
Assignment Statements
Execution rule for assignment statements:
1. Evaluate all expressions to the right of = from left to right.
8
Just executed
Next to execute
Interactive Diagram
![Page 48: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/48.jpg)
Assignment Statements
Execution rule for assignment statements:
1. Evaluate all expressions to the right of = from left to right.
2. Bind all names to the left of = to those resulting values in the current frame.
8
Just executed
Next to execute
Interactive Diagram
![Page 49: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/49.jpg)
Assignment Statements
Execution rule for assignment statements:
1. Evaluate all expressions to the right of = from left to right.
2. Bind all names to the left of = to those resulting values in the current frame.
8
Just executed
Just executed
Next to execute
Interactive Diagram
![Page 50: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/50.jpg)
Assignment Statements
Execution rule for assignment statements:
1. Evaluate all expressions to the right of = from left to right.
2. Bind all names to the left of = to those resulting values in the current frame.
8
Just executed
Just executed
Next to execute
Interactive Diagram
![Page 51: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/51.jpg)
Discussion Question 1 Solution
9
(Demo)
Interactive Diagram
![Page 52: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/52.jpg)
Discussion Question 1 Solution
9
(Demo)
Interactive Diagram
![Page 53: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/53.jpg)
Discussion Question 1 Solution
9
(Demo)
Interactive Diagram
![Page 54: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/54.jpg)
Discussion Question 1 Solution
9
(Demo)
Interactive Diagram
![Page 55: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/55.jpg)
Discussion Question 1 Solution
9
func min(...)
(Demo)
Interactive Diagram
![Page 56: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/56.jpg)
Discussion Question 1 Solution
9
func min(...) f(2, g(h(1, 5), 3))
(Demo)
Interactive Diagram
![Page 57: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/57.jpg)
Discussion Question 1 Solution
9
func min(...) f(2, g(h(1, 5), 3))
func max(...) 2
(Demo)
Interactive Diagram
![Page 58: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/58.jpg)
Discussion Question 1 Solution
9
func min(...) f(2, g(h(1, 5), 3))
g(h(1, 5), 3) func max(...) 2
(Demo)
Interactive Diagram
![Page 59: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/59.jpg)
Discussion Question 1 Solution
9
func min(...) f(2, g(h(1, 5), 3))
g(h(1, 5), 3) func max(...) 2
func min(...)
(Demo)
Interactive Diagram
![Page 60: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/60.jpg)
Discussion Question 1 Solution
9
func min(...) f(2, g(h(1, 5), 3))
g(h(1, 5), 3) func max(...) 2
h(1, 5) func min(...)
(Demo)
Interactive Diagram
![Page 61: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/61.jpg)
Discussion Question 1 Solution
9
func min(...) f(2, g(h(1, 5), 3))
g(h(1, 5), 3) func max(...) 2
h(1, 5) func min(...)
5 func max(...) 1
(Demo)
Interactive Diagram
![Page 62: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/62.jpg)
Discussion Question 1 Solution
9
func min(...) f(2, g(h(1, 5), 3))
g(h(1, 5), 3) func max(...) 2
h(1, 5) func min(...) 5
5 func max(...) 1
(Demo)
Interactive Diagram
![Page 63: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/63.jpg)
Discussion Question 1 Solution
9
func min(...) f(2, g(h(1, 5), 3))
g(h(1, 5), 3) func max(...) 2
3 h(1, 5)
func min(...) 5
5 func max(...) 1
(Demo)
Interactive Diagram
![Page 64: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/64.jpg)
Discussion Question 1 Solution
9
func min(...) f(2, g(h(1, 5), 3))
g(h(1, 5), 3) 3 func max(...) 2
3 h(1, 5)
func min(...) 5
5 func max(...) 1
(Demo)
Interactive Diagram
![Page 65: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/65.jpg)
Discussion Question 1 Solution
9
func min(...) f(2, g(h(1, 5), 3))
3
g(h(1, 5), 3) 3 func max(...) 2
3 h(1, 5)
func min(...) 5
5 func max(...) 1
(Demo)
Interactive Diagram
![Page 66: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/66.jpg)
Discussion Question 1 Solution
9
func min(...) 4 f(2, g(h(1, 5), 3))
3
g(h(1, 5), 3) 3 func max(...) 2
3 h(1, 5)
func min(...) 5
5 func max(...) 1
(Demo)
Interactive Diagram
![Page 67: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/67.jpg)
Discussion Question 1 Solution
9
func min(...) 4
3
f(2, g(h(1, 5), 3)) 3
g(h(1, 5), 3) 3 func max(...) 2
3 h(1, 5)
func min(...) 5
5 func max(...) 1
(Demo)
Interactive Diagram
![Page 68: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/68.jpg)
Discussion Question 1 Solution
9
func min(...) 4
3
f(2, g(h(1, 5), 3)) 3
g(h(1, 5), 3) 3 func max(...) 2
3 h(1, 5)
func min(...) 5
5 func max(...) 1 3
(Demo)
Interactive Diagram
![Page 69: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/69.jpg)
Defining Functions
![Page 70: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/70.jpg)
Defining Functions
Assignment is a simple means of abstraction: binds names to values
Function definition is a more powerful means of abstraction: binds names to expressions
11
![Page 71: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/71.jpg)
Defining Functions
Assignment is a simple means of abstraction: binds names to values
Function definition is a more powerful means of abstraction: binds names to expressions
<name>(<formal parameters>):
return <return expression>
>>> def
11
![Page 72: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/72.jpg)
Defining Functions
Assignment is a simple means of abstraction: binds names to values
Function definition is a more powerful means of abstraction: binds names to expressions
<name>(<formal parameters>):
return <return expression>
>>> def
Function signature indicates how many arguments a function takes
11
![Page 73: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/73.jpg)
Defining Functions
Assignment is a simple means of abstraction: binds names to values
Function definition is a more powerful means of abstraction: binds names to expressions
<name>(<formal parameters>):
return <return expression>
>>> def
Function signature indicates how many arguments a function takes
Function body defines the computation performed when the function is applied
11
![Page 74: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/74.jpg)
Defining Functions
Assignment is a simple means of abstraction: binds names to values
Function definition is a more powerful means of abstraction: binds names to expressions
<name>(<formal parameters>):
return <return expression>
>>> def
Execution procedure for def statements:
Function signature indicates how many arguments a function takes
Function body defines the computation performed when the function is applied
11
![Page 75: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/75.jpg)
Defining Functions
Assignment is a simple means of abstraction: binds names to values
Function definition is a more powerful means of abstraction: binds names to expressions
<name>(<formal parameters>):
return <return expression>
>>> def
Execution procedure for def statements:
1. Create a function with signature <name>(<formal parameters>)
Function signature indicates how many arguments a function takes
Function body defines the computation performed when the function is applied
11
![Page 76: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/76.jpg)
Defining Functions
Assignment is a simple means of abstraction: binds names to values
Function definition is a more powerful means of abstraction: binds names to expressions
<name>(<formal parameters>):
return <return expression>
>>> def
Execution procedure for def statements:
1. Create a function with signature <name>(<formal parameters>)
2. Set the body of that function to be everything indented after the first line
Function signature indicates how many arguments a function takes
Function body defines the computation performed when the function is applied
11
![Page 77: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/77.jpg)
Defining Functions
Assignment is a simple means of abstraction: binds names to values
Function definition is a more powerful means of abstraction: binds names to expressions
<name>(<formal parameters>):
return <return expression>
>>> def
Execution procedure for def statements:
1. Create a function with signature <name>(<formal parameters>)
2. Set the body of that function to be everything indented after the first line
3. Bind <name> to that function in the current frame
Function signature indicates how many arguments a function takes
Function body defines the computation performed when the function is applied
11
![Page 78: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/78.jpg)
Calling User-Defined Functions
12Interactive Diagram
![Page 79: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/79.jpg)
Calling User-Defined Functions
Procedure for calling/applying user-defined functions (version 1):
12Interactive Diagram
![Page 80: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/80.jpg)
Calling User-Defined Functions
Procedure for calling/applying user-defined functions (version 1):
1. Add a local frame, forming a new environment
12Interactive Diagram
![Page 81: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/81.jpg)
Calling User-Defined Functions
Procedure for calling/applying user-defined functions (version 1):
1. Add a local frame, forming a new environment2. Bind the function's formal parameters to its arguments in that frame
12Interactive Diagram
![Page 82: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/82.jpg)
Calling User-Defined Functions
Procedure for calling/applying user-defined functions (version 1):
1. Add a local frame, forming a new environment2. Bind the function's formal parameters to its arguments in that frame3. Execute the body of the function in that new environment
12Interactive Diagram
![Page 83: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/83.jpg)
Calling User-Defined Functions
Procedure for calling/applying user-defined functions (version 1):
1. Add a local frame, forming a new environment2. Bind the function's formal parameters to its arguments in that frame3. Execute the body of the function in that new environment
12Interactive Diagram
![Page 84: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/84.jpg)
Calling User-Defined Functions
Procedure for calling/applying user-defined functions (version 1):
1. Add a local frame, forming a new environment2. Bind the function's formal parameters to its arguments in that frame3. Execute the body of the function in that new environment
Built-in function
12Interactive Diagram
![Page 85: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/85.jpg)
Calling User-Defined Functions
Procedure for calling/applying user-defined functions (version 1):
1. Add a local frame, forming a new environment2. Bind the function's formal parameters to its arguments in that frame3. Execute the body of the function in that new environment
Built-in function
User-defined function
12Interactive Diagram
![Page 86: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/86.jpg)
Calling User-Defined Functions
Procedure for calling/applying user-defined functions (version 1):
1. Add a local frame, forming a new environment2. Bind the function's formal parameters to its arguments in that frame3. Execute the body of the function in that new environment
Local frame
Built-in function
User-defined function
12Interactive Diagram
![Page 87: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/87.jpg)
Calling User-Defined Functions
Procedure for calling/applying user-defined functions (version 1):
1. Add a local frame, forming a new environment2. Bind the function's formal parameters to its arguments in that frame3. Execute the body of the function in that new environment
Local frame
Original name of function called
Built-in function
User-defined function
12Interactive Diagram
![Page 88: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/88.jpg)
Calling User-Defined Functions
Procedure for calling/applying user-defined functions (version 1):
1. Add a local frame, forming a new environment2. Bind the function's formal parameters to its arguments in that frame3. Execute the body of the function in that new environment
Local frame
Original name of function called
Formal parameter bound to argument
Built-in function
User-defined function
12Interactive Diagram
![Page 89: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/89.jpg)
Calling User-Defined Functions
Procedure for calling/applying user-defined functions (version 1):
1. Add a local frame, forming a new environment2. Bind the function's formal parameters to its arguments in that frame3. Execute the body of the function in that new environment
Local frame
Original name of function called
Formal parameter bound to argument Return value
(not a binding!)
Built-in function
User-defined function
12Interactive Diagram
![Page 90: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/90.jpg)
Calling User-Defined Functions
13
Procedure for calling/applying user-defined functions (version 1):
1. Add a local frame, forming a new environment 2. Bind the function's formal parameters to its arguments in that frame 3. Execute the body of the function in that new environment
Interactive Diagram
![Page 91: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/91.jpg)
Calling User-Defined Functions
A function’s signature has all the information needed to create a local frame
13
Procedure for calling/applying user-defined functions (version 1):
1. Add a local frame, forming a new environment 2. Bind the function's formal parameters to its arguments in that frame 3. Execute the body of the function in that new environment
Interactive Diagram
![Page 92: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/92.jpg)
Calling User-Defined Functions
A function’s signature has all the information needed to create a local frame
13
Procedure for calling/applying user-defined functions (version 1):
1. Add a local frame, forming a new environment 2. Bind the function's formal parameters to its arguments in that frame 3. Execute the body of the function in that new environment
Interactive Diagram
![Page 93: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/93.jpg)
Calling User-Defined Functions
A function’s signature has all the information needed to create a local frame
13
Procedure for calling/applying user-defined functions (version 1):
1. Add a local frame, forming a new environment 2. Bind the function's formal parameters to its arguments in that frame 3. Execute the body of the function in that new environment
Interactive Diagram
![Page 94: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/94.jpg)
Looking Up Names In Environments
14
![Page 95: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/95.jpg)
Looking Up Names In Environments
Every expression is evaluated in the context of an environment.
14
![Page 96: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/96.jpg)
Looking Up Names In Environments
Every expression is evaluated in the context of an environment.
So far, the current environment is either:
14
![Page 97: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/97.jpg)
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
14
![Page 98: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/98.jpg)
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.
14
![Page 99: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/99.jpg)
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:
14
![Page 100: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/100.jpg)
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.
14
![Page 101: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/101.jpg)
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.
14
![Page 102: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/102.jpg)
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:
14
![Page 103: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/103.jpg)
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.
14
![Page 104: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/104.jpg)
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.(Built-in names like “max” are in the global frame too, but we don’t draw them in environment diagrams.)
14
![Page 105: 61A Lecture 2 · Discussion Question 1 What is the value of the final expression in this sequence? 5. ... Arrows indicate evaluation order Code (left): Frames (right): Environment](https://reader033.vdocuments.us/reader033/viewer/2022060415/5f1351b1bb0c4115e926b9b5/html5/thumbnails/105.jpg)
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.(Built-in names like “max” are in the global frame too, but we don’t draw them in environment diagrams.)
(Demo)14