CS 61A Discussion 2
Environments and Higher Order Functions
Attendance: links.cs61a.org/albert-disc Slides: albertxu.xyz/teaching/cs61a/
Albert Xu Kaavya Shah
CS 61A Discussion 2 Environments and Higher Order Functions Albert - - PowerPoint PPT Presentation
CS 61A Discussion 2 Environments and Higher Order Functions Albert Xu Kaavya Shah Attendance: links.cs61a.org/albert-disc Slides: albertxu.xyz/teaching/cs61a/ Announcements Higher order functions! Higher order functions! just kidding i hate
Attendance: links.cs61a.org/albert-disc Slides: albertxu.xyz/teaching/cs61a/
Albert Xu Kaavya Shah
just kidding i hate this name. I think this just makes this idea really confusing.
>>> f = make_power(3) >>> f(5)
>>> f = make_power(3) >>> f(5) 125
>>> apply_twice(square, 3) 81
let’s look at a function we’ve already seen.
draw an environment diagram. let’s look at a function we’ve already seen.
let’s look at a function we’ve already seen. def statement procedure:
1) Write the function on the right side, with appropriate intrinsic name + parent 2) Write the name of the function on the left in current frame 3) Draw an arrow to the function object on the right! 4) Skip the body.
let’s look at a function we’ve already seen. assignment statement procedure:
1) Evaluate the right hand side 2) Bind that value to a name on the left 3) If the name doesn’t exist in the current frame, add it! Otherwise change the current value
let’s look at a function we’ve already seen. function call procedure:
1) Evaluate the operator 2) Evaluate the operands 3) Open the call frame 4) Bind the parameters 5) Evaluate the body
let’s look at a function we’ve already seen. function call procedure:
1) Evaluate the operator 2) Evaluate the operands 3) Open the call frame 4) Bind the parameters 5) Evaluate the body *don’t open a frame for built-in functions!
let’s look at a function we’ve already seen. function call procedure:
1) Evaluate the operator 2) Evaluate the operands 3) Open the call frame 4) Bind the parameters 5) Evaluate the body
hi
*don’t open a frame for built-in functions!
let’s look at a function we’ve already seen. function call procedure:
1) Evaluate the operator 2) Evaluate the operands 3) Open the call frame 4) Bind the parameters 5) Evaluate the body
hi None
*don’t open a frame for built-in functions!
let’s look at a function we’ve already seen. hi None …and we’re done!
Attendance: links.cs61a.org/albert-disc Slides: albertxu.xyz/teaching/cs61a/